Java 类android.renderscript.Element 实例源码

项目:Tribe    文件:BlurBitmap.java   
public static Bitmap blurMax(Context context, Bitmap image) {
    // 计算图片缩小后的长宽
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);
    // 将缩小后的图片做为预渲染的图片。
    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    // 创建一张渲染后的输出图片。
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
    // 创建RenderScript内核对象
    RenderScript rs = RenderScript.create(context);
    // 创建一个模糊效果的RenderScript的工具对象
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    // 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间。
    // 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去。
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    // 设置渲染的模糊程度, 25f是最大模糊度
    blurScript.setRadius(25f);
    // 设置blurScript对象的输入内存
    blurScript.setInput(tmpIn);
    // 将输出数据保存到输出内存中
    blurScript.forEach(tmpOut);
    // 将数据填充到Allocation中
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}
项目:Songify    文件:BlurBackground.java   
private static Bitmap blur(Context context, Bitmap image) {

        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

        Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(context);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }
项目:GitHub    文件:ImageUtils.java   
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src     源图片
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(final Bitmap src,
                                      @FloatRange(from = 0, to = 25, fromInclusive = false) final float radius,
                                      final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    Bitmap ret = recycle ? src : src.copy(src.getConfig(), true);
    try {
        rs = RenderScript.create(Utils.getApp());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, ret, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(ret);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return ret;
}
项目:pracler    文件:ImageUtils.java   
public static Bitmap blur(Context context, Bitmap sentBitmap, int radius) {

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
            Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);

            final RenderScript rs = RenderScript.create(context);
            final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
                    Allocation.USAGE_SCRIPT);
            final Allocation output = Allocation.createTyped(rs, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setRadius(radius); //0.0f ~ 25.0f
            script.setInput(input);
            script.forEach(output);
            output.copyTo(bitmap);
            return bitmap;
        } else {
            return sentBitmap;
        }
    }
项目:PrivacyStreams    文件:ImageUtils.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blur(UQI uqi, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(uqi.getContext());
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
项目:Android-UtilCode    文件:ImageUtils.java   
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src     源图片
 * @param radius  模糊半径(0...25)
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    try {
        rs = RenderScript.create(Utils.getContext());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
项目:HL4A    文件:图片工具.java   
public static Bitmap 模糊(Bitmap $图片,int $半径) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Bitmap bitmap = $图片.copy($图片.getConfig(), true);
        final RenderScript rs = RenderScript.create(上下文工具.取全局上下文());
        final Allocation input = Allocation.createFromBitmap(rs, $图片, Allocation.MipmapControl.MIPMAP_NONE,                                                                                      Allocation.USAGE_SCRIPT);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        script.setRadius($半径);
        script.setInput(input);
        script.forEach(output);
        output.copyTo(bitmap);

        // clean up renderscript resources
        rs.destroy();
        input.destroy();
        output.destroy();
        script.destroy();

        return bitmap;
    }
    return null;
}
项目:KomaMusic    文件:ImageLoader.java   
public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {

        RenderScript rs = RenderScript.create(context);
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = inSampleSize;

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] imageInByte = stream.toByteArray();
        ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
        Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);

        final Allocation input = Allocation.createFromBitmap(rs, blurTemplate);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        script.setRadius(8f);
        script.setInput(input);
        script.forEach(output);
        output.copyTo(blurTemplate);

        return new BitmapDrawable(context.getResources(), blurTemplate);
    }
项目:NeoStream    文件:ChannelFragment.java   
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true);

    Allocation input = Allocation.createFromBitmap(
            rs,
            blurredBitmap,
            Allocation.MipmapControl.MIPMAP_FULL,
            Allocation.USAGE_SHARED
    );
    Allocation output = Allocation.createTyped(rs, input.getType());

    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setInput(input);
    script.setRadius(15);
    script.forEach(output);

    output.copyTo(blurredBitmap);

    toTransform.recycle();

    return blurredBitmap;
}
项目:AndroidUtilCode-master    文件:ImageUtils.java   
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src    源图片
 * @param radius 模糊半径(0...25)
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    try {
        rs = RenderScript.create(Utils.getContext());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap one(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix1=ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix1.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    -0.33f, -0.33f, -0.33f, 1.0f,
                    -0.59f, -0.59f, -0.59f, 1.0f,
                    -0.11f, -0.11f, -0.11f, 1.0f,
                    1.0f, 1.0f, 1.0f, 1.0f
            }));
    colorMatrix1.forEach(inputAllocation,outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap three(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix3 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix3.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    0f, 0f, 0f, 0f,
                    0f, 0.78f, 0f, 0f,
                    0f, 0f, 1f, 0f,
                    0f, 0f, 0f, 1f,
            }));
    colorMatrix3.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap four(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix4 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix4.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    0.3f, 0f, 0f, 0f,
                    0f, 0.65f, 0f, 0f,
                    0f, 0f, 0.49f, 0f,
                    0f, 0f, 0f, 1f


            }));
    colorMatrix4.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap five(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final  ScriptIntrinsicColorMatrix colorMatrix5 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix5.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    -0.359705309629158f, 0.377252728606377f, 0.663841667303255f, 0f,
                    1.56680818833214f, 0.456668209492391f, 1.12613917506705f, 0f,
                    -0.147102878702981f, 0.226079061901232f, -0.729980842370303f, 0f,
                    0f, 0f, 0f, 1f
            }));
    colorMatrix5.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap six(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix6 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix6.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1.2f, 0.1f, 0.2f, 0.7f,

                    0.7f, 1f, 0f, -0.5f,
                    -0.7f, 0.2f, 0.5f, 1.3f,
                    0, -0.1f, 0f, 0.9f
            }));
    colorMatrix6.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap seven(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final  ScriptIntrinsicColorMatrix colorMatrix7 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix7.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1.22994596833595f, 0.0209523774645382f, 0.383244054685119f, 0f,
                    0.450138899443543f, 1.18737418804171f, -0.106933249401007f, 0f
                    - 0.340084867779496f, 0.131673434493755f, 1.06368919471589f, 0f,
                    0f, 0f, 0f,
                    11.91f, 11.91f, 11.91f, 0f}));
    colorMatrix7.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap eight(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final  ScriptIntrinsicColorMatrix colorMatrix8 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix8.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1.44f, 0f, 0f, 0f,
                    0f, 1.44f, 0f, 0f,
                    0f, 0f, 1.44f, 0f,
                    0f, 0f, 0f, 1f,


            }));
    colorMatrix8.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap nine(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final  ScriptIntrinsicColorMatrix colorMatrix9 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix9.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    -2f, -1f, 1f, -2f,
                    0f, -2f, 0f, 1f,
                    0f, 0f, -1f, 1f,
                    0f, 0f, 0f, 1f
            }));
    colorMatrix9.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap ten(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final   ScriptIntrinsicColorMatrix colorMatrix10 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix10.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1f, 0f, 0.1f, -0.1f,
                    0f, 1f, 0.2f, 0f,
                    0f, 0f, 1.3f, 0f,
                    0f, 0f, 0f, 1

            }));
    colorMatrix10.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap eleven(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final   ScriptIntrinsicColorMatrix colorMatrix11 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix11.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    1.72814708519562f, -0.412104992562475f, 0.541145007437525f, 0f,
                    0.289378264402959f, 1.18835534216106f, -1.17637173559704f, 0f,
                    -1.01752534959858f, 0.223749650401417f, 1.63522672815952f, 0f,
                    0f, 0f, 0f, 1f


            }));
    colorMatrix11.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap twelve(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix12 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix12.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {
                    .309f, .409f, .309f, 0f,
                    .609f, .309f, .409f, 0f,
                    0.42f, .42f, .2f, 0f,
                    0f, 0f, 0f, 1f


            }));
    colorMatrix12.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap thirteen(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicConvolve3x3 convolve1 = ScriptIntrinsicConvolve3x3.create(renderScript, Element.U8_4(renderScript));
    convolve1.setInput(inputAllocation);
    convolve1.setCoefficients(new float[]
            {
                    -2, -1, 0,
                    -1, 1, 1,
                    0, 1, 2
            });
    convolve1.forEach(outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap fourteen(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicConvolve3x3 convolve2 = ScriptIntrinsicConvolve3x3.create(renderScript, Element.U8_4(renderScript));
    convolve2.setInput(inputAllocation);
    convolve2.setCoefficients(new float[]
            {
                    .2f, .3f, .2f, .1f, .1f, .1f, .2f, .3f, .2f,

            });
    convolve2.forEach(outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap fifteen(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix13 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix13.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {

                    2.10279132254252f,  -0.298212630531356f,       0.42128146417712f,   0f,
                    0.222897572029231f,     1.68701190285368f,     -0.883421304780577f,   0f,
                    -0.765688894571747f,   0.171200727677677f,    2.02213984060346f,     0f,
                    0                          ,  0                 ,0                ,1f


            }));
    colorMatrix13.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:FilterLibrary    文件:PhotoFilter.java   
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public Bitmap sixteen(Context context, Bitmap bitmap){
    renderScript=RenderScript.create(context);
    outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    inputAllocation=Allocation.createFromBitmap(renderScript,bitmap);
    outputAllocation=Allocation.createTyped(renderScript,inputAllocation.getType());
    final ScriptIntrinsicColorMatrix colorMatrix14 = ScriptIntrinsicColorMatrix.create(renderScript, Element.U8_4(renderScript));
    colorMatrix14.setColorMatrix(new android.renderscript.Matrix4f(new float[]
            {

                    1.27488526960083f, -0.228511311848763f,   0.441088688151237f,  0,
                    0.323664244263542f,  0.955140825713134f,  -0.705935755736458f,  0,
                    -0.698549513864371f, 0.173370486135629f ,  1.16484706758522f  ,0,
                    0,0,0,1


            }));
    colorMatrix14.forEach(inputAllocation, outputAllocation);
    outputAllocation.copyTo(outBitmap);
    return outBitmap;
}
项目:BBSSDK-for-Android    文件:ImageUtils.java   
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src     源图片
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(final Bitmap src, final float radius, final boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    RenderScript rs = null;
    Bitmap ret = recycle ? src : src.copy(src.getConfig(), true);
    try {
        rs = RenderScript.create(Utils.getApp());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, ret, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(ret);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return ret;
}
项目:Mp3Player    文件:MusicPlayerActivity.java   
public Bitmap blur(Bitmap image) {
    if (null == image) return null;

    Bitmap outputBitmap = Bitmap.createBitmap(image);
    final RenderScript renderScript = RenderScript.create(this);
    Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
    Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);

    //Intrinsic Gausian blur filter
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}
项目:HutHelper    文件:CommUtil.java   
/**
 * 图片高斯模糊
 *
 * @param context
 * @param bitmap
 * @return
 */
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    //用需要创建高斯模糊bitmap创建一个空的bitmap
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    // 初始化Renderscript,该类提供了RenderScript context,创建其他RS类之前必须先创建这个类,其控制RenderScript的初始化,资源管理及释放
    RenderScript rs = RenderScript.create(context);
    // 创建高斯模糊对象
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    // 创建Allocations,此类是将数据传递给RenderScript内核的主要方 法,并制定一个后备类型存储给定类型
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    //设定模糊度(注:Radius最大只能设置25.f)
    blurScript.setRadius(15f);
    // Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    allOut.copyTo(outBitmap);
    rs.destroy();
    return outBitmap;
}
项目:LJFramework    文件:ImageUtils.java   
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param context 上下文
 * @param src 源图片
 * @param radius 模糊半径(0...25)
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Context context, Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    RenderScript rs = null;
    try {
        rs = RenderScript.create(context);
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation
                .createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur
                .create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
项目:TicketView    文件:TicketView.java   
private void generateShadow() {
    if (isJellyBeanAndAbove()) {
        if (mShadowBlurRadius == 0f) return;

        if (mShadow == null) {
            mShadow = Bitmap.createBitmap(getWidth(), getHeight(), ALPHA_8);
        } else {
            mShadow.eraseColor(TRANSPARENT);
        }
        Canvas c = new Canvas(mShadow);
        c.drawPath(mPath, mShadowPaint);
        if (mShowBorder) {
            c.drawPath(mPath, mShadowPaint);
        }
        RenderScript rs = RenderScript.create(getContext());
        ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8(rs));
        Allocation input = Allocation.createFromBitmap(rs, mShadow);
        Allocation output = Allocation.createTyped(rs, input.getType());
        blur.setRadius(mShadowBlurRadius);
        blur.setInput(input);
        blur.forEach(output);
        output.copyTo(mShadow);
        input.destroy();
        output.destroy();
    }
}
项目:style-transfer    文件:FindRegion.java   
public Rect findMatch(ScriptC_find_region findRegion, RenderScript mRs, Bitmap image) {
    long time = System.nanoTime();

    Allocation border_coords;

    border_coords = allocFloat2(mPointsXY, mRs);
    Allocation aImage = Allocation.createFromBitmap(mRs, image);
    Allocation ret = Allocation.createSized(mRs, Element.I32_2(mRs), 1);

    findRegion.invoke_findRegion(border_coords, aImage, image.getWidth(), image.getHeight(), ret);

    int[] mina = new int[2];
    ret.copyTo(mina);
    mCutOffsetX = mina[0];
    mCutOffsetY = mina[1];
    Log.v(TAG, "New best location = " + mCutOffsetX + ", " + mCutOffsetY);
    Log.v(TAG, "Time to find replacement= " + (System.nanoTime() - time) / 1E6f + "ms");

    return mRoiBounds;
}
项目:RabbitCloud    文件:RenderScriptHelper.java   
public static Bitmap rsBlur(Context context, Bitmap source, int radius) {

        // 计算图片缩小后的长宽
        int width = Math.round(source.getWidth() * BITMAP_SCALE);
        int height = Math.round(source.getHeight() * BITMAP_SCALE);

        // 将缩小后的图片做为预渲染的图片
        Bitmap inputBitmap = Bitmap.createScaledBitmap(source, width, height, false);

        RenderScript renderScript = RenderScript.create(context);
        final Allocation input = Allocation.createFromBitmap(renderScript, inputBitmap);
        final Allocation outPut = Allocation.createTyped(renderScript, input.getType());

        ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript,
                Element.U8_4(renderScript));
        scriptIntrinsicBlur.setInput(input);
        scriptIntrinsicBlur.setRadius(radius);
        scriptIntrinsicBlur.forEach(outPut);
        outPut.copyTo(inputBitmap);
        renderScript.destroy();

        return inputBitmap;
    }
项目:GravityBox    文件:Utils.java   
public static Bitmap blurBitmap(Context context, Bitmap bmp, float radius) {
    Bitmap out = Bitmap.createBitmap(bmp);
    RenderScript rs = RenderScript.create(context);
    radius = Math.min(Math.max(radius, 0), 25);

    Allocation input = Allocation.createFromBitmap(
            rs, bmp, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(rs, input.getType());

    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setInput(input);
    script.setRadius(radius);
    script.forEach(output);

    output.copyTo(out);

    rs.destroy();
    return out;
}
项目:MobiRNN-EMDL17    文件:Model.java   
private void allocIntermediateVariables() {
    Allocation cAlloc = Allocation.createSized(mRs, Element.F32(mRs), hidden_units);
    scriptC_main.bind_c(cAlloc);

    Allocation hAlloc = Allocation.createSized(mRs, Element.F32(mRs), hidden_units);
    scriptC_main.bind_h(hAlloc);

    Allocation inputConcatAlloc = Allocation.createSized(mRs, Element.F32(mRs),
            hidden_units * 2);
    scriptC_main.bind_input_concat(inputConcatAlloc);

    Allocation linearResultAlloc = Allocation.createSized(mRs, Element.F32(mRs),
            hidden_units * 4);
    scriptC_main.bind_linear_result(linearResultAlloc);

}
项目:HeadlineNews    文件:ImageUtils.java   
/**
 * renderScript模糊图片
 * <p>API大于17</p>
 *
 * @param src    源图片
 * @param radius 模糊半径(0...25)
 * @return 模糊后的图片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(final Bitmap src,
                                      @FloatRange(from = 0, to = 25, fromInclusive = false) final float radius) {
    if (isEmptyBitmap(src)) return null;
    RenderScript rs = null;
    try {
        rs = RenderScript.create(Utils.getContext());
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation
                .USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
项目:RootPGPExplorer    文件:TabsFragmentOne.java   
public static Bitmap blur(Context context, Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

        Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(context);
        ScriptIntrinsicBlur theIntrinsic = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);
        }else{
            outputBitmap= BlurHelper.doBlur(image,(int)BLUR_RADIUS,false);
        }


        return outputBitmap;

}
项目:AndroRW    文件:BlurBuilder.java   
public static Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
项目:OrionPreview    文件:BlurAnimation.java   
public Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
项目:Rocket    文件:ImageUtils.java   
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    if (context == null || bitmap == null) return null;

    Bitmap blurredBitmap;
    try {
        blurredBitmap = Bitmap.createBitmap(bitmap);
    } catch (OutOfMemoryError e) {
        return null;
    }

    RenderScript renderScript = RenderScript.create(context);
    Allocation input = Allocation.createFromBitmap(renderScript, bitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(renderScript, input.getType());
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));

    script.setInput(input);
    script.setRadius(20);

    script.forEach(output);
    output.copyTo(blurredBitmap);

    return blurredBitmap;
}
项目:Bagels    文件:ImageUtils.java   
@Nullable
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    if (context == null || bitmap == null) return null;

    Bitmap blurredBitmap;
    try {
        blurredBitmap = Bitmap.createBitmap(bitmap);
    } catch (OutOfMemoryError e) {
        return null;
    }

    RenderScript renderScript = RenderScript.create(context);
    Allocation input = Allocation.createFromBitmap(renderScript, bitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(renderScript, input.getType());
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));

    script.setInput(input);
    script.setRadius(20);

    script.forEach(output);
    output.copyTo(blurredBitmap);

    return blurredBitmap;
}