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
Post a Comment