Android Blur with RenderScript -


i try make gaussian blur on android bitmap error:

rsassert failed: !mtypes.size() , rsassert failed: !melements.size()

here code :

public bitmap blurbitmap(bitmap src) {     bitmap outbitmap = src.copy(src.getconfig(), true);      final renderscript rs = renderscript.create(this);     final allocation input = allocation.createfrombitmap(rs, src);     final allocation output = allocation.createfrombitmap(rs, outbitmap);      final scriptintrinsicblur script =             scriptintrinsicblur.create(rs, element.u8_4(rs));     script.setradius(25f);     script.setinput(input);     script.foreach(output);     output.copyto(outbitmap);      rs.destroy();      return outbitmap; } 

note used android.support.v8.renderscript ensure compatibility android lower versions.

someone have idea fix it?

thanks.

martin

the element arguments of scriptintrinsicblur should same of allocation's element, should use allocation.getelement(), rather direct element.u8_4(rs).

final scriptintrinsicblur script =     scriptintrinsicblur.create(rs, input.getelement()); 

and might want move final class private member, since of them might different every time bitmap different.

and fyi, script.setradius(25f) way high, cause slow calculation. if need such heavy blur, might consider scale down original bitmap @ level, , blur it, scale canvas, faster heavy blur huge image.

one more thing, if don't care keep original bitmap, allocation of input , output can same one, might save memory.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -