How can I use Renderscript to blur a large image into a smaller one?


Suppose I have a fairly large bitmap and I want to blur it into a smaller bitmap.

I am really asking this because I am having strange glitches inside Renderscript itself on some rare devices, so maybe this is something with the input (which in fact I already made sure it is quite small):

java.lang.OutOfMemoryError: Failed to allocate a 1920169996 byte allocation with 16777216 free bytes and 67MB until OOM
   at android.renderscript.RenderScript$


This is strange because there is no way for the input bitmap to be that big (almost 2GB ?!).


The code below tries to do this, but for some reason the output raster map only occupies the top left area of ​​the large raster image:

        outputBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(outputBitmap);
        canvas.drawBitmap(srcBitmap, 0, 0, null);
        Allocation overlayAlloc = Allocation.createFromBitmap(rs, outputBitmap, MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE);
        ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        return outputBitmap;



How could this be? What should be done to fix this? Obviously I could create a new bitmap as input and make it the same size as the small one, but this creates another bitmap that takes up memory and I would like to avoid it.


source to share

1 answer

Before trying to save memory without generating small bitmaps try checking this out:

You can save time if you scale down the image, blur it, and then scale it up - there isn't much difference between complex blur and sharp blur, but it saves time.

PS. also you can check the renderscript sample from this thread. PSS. also you can check this thread about blur: Fast Blur Bitmaps for Android SDK



All Articles