1. 程式人生 > >android-support-v8 建立高斯模糊

android-support-v8 建立高斯模糊

public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {
        final 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); script.setInput(input); script.forEach
(output); output.copyTo(bitmap); sentBitmap.recycle(); rs.destroy(); input.destroy(); output.destroy(); script.destroy(); return bitmap; }

radius: 模糊度
sentBitmap: 源bitmap