mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-30 05:12:45 +08:00
Add null checking the context.
This commit is contained in:
parent
260f91e291
commit
eef0be6b92
@ -74,6 +74,10 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||||
|
Context context = mContext.get();
|
||||||
|
if(context == null) {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
Bitmap source = resource.get();
|
Bitmap source = resource.get();
|
||||||
|
|
||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
@ -92,7 +96,7 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
|||||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||||
canvas.drawBitmap(source, 0, 0, paint);
|
canvas.drawBitmap(source, 0, 0, paint);
|
||||||
|
|
||||||
RenderScript rs = RenderScript.create(mContext.get());
|
RenderScript rs = RenderScript.create(context);
|
||||||
Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||||
Allocation.USAGE_SCRIPT);
|
Allocation.USAGE_SCRIPT);
|
||||||
Allocation output = Allocation.createTyped(rs, input.getType());
|
Allocation output = Allocation.createTyped(rs, input.getType());
|
||||||
@ -103,8 +107,6 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
|||||||
blur.forEach(output);
|
blur.forEach(output);
|
||||||
output.copyTo(bitmap);
|
output.copyTo(bitmap);
|
||||||
|
|
||||||
source.recycle();
|
|
||||||
resource.recycle();
|
|
||||||
rs.destroy();
|
rs.destroy();
|
||||||
|
|
||||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user