Reputation: 891
I have use androidx with blur image, but when run android api< 19 crash app. When i run with android>19, i run normal,not crash app and if i use android normal with "android.support.v8.renderscript" no crash app. At build.gradle. I have add :
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
Code app:
public static Bitmap blurBitmap(Bitmap bitmap,
float radius) { //Create renderscript
RenderScript
rs = RenderScript.create(MyApplication.getInstance());
//Create allocation from Bitmap
Allocation allocation = Allocation.createFromBitmap(rs,
bitmap);
Type t = allocation.getType();
//Create allocation with the same type
Allocation blurredAllocation = Allocation.createTyped(rs,
t);
//Create script
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8(rs));
//Set blur radius (maximum 25.0)
blurScript.setRadius(radius);
//Set input for script
blurScript.setInput(allocation);
//Call script for output allocation
blurScript.forEach(blurredAllocation);
//Copy script result into bitmap
blurredAllocation.copyTo(bitmap);
//Destroy everything to free memory
allocation.destroy();
blurredAllocation.destroy();
blurScript.destroy();
t.destroy();
rs.destroy();
return bitmap;
}
Upvotes: 2
Views: 1390
Reputation: 418
Edit: This issue is now fixed in the latest build tools. I've verified this by upgrading compile sdk to API 29 and build tools to 29.0.2.
This has nothing to do with your implementation. It's a bug in the androidx library and in fact, it happens for me even on API 21 so it might have a bigger impact than you've experienced.
Someone has already filed issues here and here. I've been following on the issue for quite sometime unfortunately there isn't much progress going on. This is currently a showstopper for me to migrate to AndroidX for many of my projects.
Upvotes: 3
Reputation: 2650
The Element.U8
argument for ScriptIntrinsicBlur.create()
is not correct.
The ScriptIntrinsicBlur
is expecting an Allocation
with elements of type Element.U8
, but a Bitmap
-backed Allocation
has elements of type Element.RGBA_8888
(a.k.a Element.U8_4
).
try:
ScriptIntrinsicBlur.create(rs, Element.RGBA_8888(rs))
or in general:
ScriptIntrinsicBlur.create(rs, allocation.getElement())
Upvotes: 0