图片模糊代码:
public class BlurBitmap { private static final float BITMAP_SCALE = 0.4f; private static final float BLUR_RADIUS = 25f; 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 renderScript = RenderScript.create(context); ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript)); Allocation tmpIn = Allocation.createCubemapFromBitmap(renderScript, inputBitmap); Allocation tmpOut = Allocation.createCubemapFromBitmap(renderScript, outputBitmap); scriptIntrinsicBlur.setRadius(BLUR_RADIUS); scriptIntrinsicBlur.setInput(tmpIn); scriptIntrinsicBlur.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; } }