mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-11 01:04:04 +08:00
Additional resource cleanup in RSBlur
When the blur is finished, the input, output, and blur are all destroyed, along with the renderscript instance. This resolves a strictmode 'resource acquired but never released' violation.
This commit is contained in:
parent
c3f09cdd0d
commit
a139c21d31
@ -31,14 +31,16 @@ public class RSBlur {
|
|||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||||
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
|
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
|
||||||
RenderScript rs = null;
|
RenderScript rs = null;
|
||||||
|
Allocation input = null;
|
||||||
|
Allocation output = null;
|
||||||
|
ScriptIntrinsicBlur blur = null;
|
||||||
try {
|
try {
|
||||||
rs = RenderScript.create(context);
|
rs = RenderScript.create(context);
|
||||||
rs.setMessageHandler(new RenderScript.RSMessageHandler());
|
rs.setMessageHandler(new RenderScript.RSMessageHandler());
|
||||||
Allocation input =
|
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||||
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
|
||||||
Allocation.USAGE_SCRIPT);
|
Allocation.USAGE_SCRIPT);
|
||||||
Allocation output = Allocation.createTyped(rs, input.getType());
|
output = Allocation.createTyped(rs, input.getType());
|
||||||
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||||
|
|
||||||
blur.setInput(input);
|
blur.setInput(input);
|
||||||
blur.setRadius(radius);
|
blur.setRadius(radius);
|
||||||
@ -48,6 +50,15 @@ public class RSBlur {
|
|||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
rs.destroy();
|
rs.destroy();
|
||||||
}
|
}
|
||||||
|
if (input != null) {
|
||||||
|
input.destroy();
|
||||||
|
}
|
||||||
|
if (output != null) {
|
||||||
|
output.destroy();
|
||||||
|
}
|
||||||
|
if (blur != null) {
|
||||||
|
blur.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user