Fast Bitmap Blur For Android SDK

后端 未结 19 1741
情书的邮戳
情书的邮戳 2020-11-22 08:53

Currently in an Android application that I\'m developing I\'m looping through the pixels of an image to blur it. This takes about 30 seconds on a 640x480 image.

W

19条回答
  •  天涯浪人
    2020-11-22 09:27

    Nicolas POMEPUY advice. I think this link will be helpful: Blur effect for Android design

    Sample project at github

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private static Bitmap fastblur16(Bitmap source, int radius, Context ctx) {    
        Bitmap bitmap = source.copy(source.getConfig(), true);    
        RenderScript rs = RenderScript.create(ctx);
        Allocation input = Allocation.createFromBitmap(rs, source, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        script.setRadius(radius);
        script.setInput(input);
        script.forEach(output);
        output.copyTo(bitmap);
        return bitmap;
    }
    

提交回复
热议问题