mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-08 07:24:05 +08:00
Use WeakReference.
This commit is contained in:
parent
36ceccb38e
commit
260f91e291
@ -29,13 +29,14 @@ import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class BlurTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private static int MAX_RADIUS = 25;
|
||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||
|
||||
private Context mContext;
|
||||
private WeakReference<Context> mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
|
||||
private int mRadius;
|
||||
@ -58,14 +59,14 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
||||
}
|
||||
|
||||
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
||||
mContext = context;
|
||||
mContext = new WeakReference<>(context);
|
||||
mBitmapPool = pool;
|
||||
mRadius = radius;
|
||||
mSampling = sampling;
|
||||
}
|
||||
|
||||
public BlurTransformation(Context context, int radius, int sampling) {
|
||||
mContext = context;
|
||||
mContext = new WeakReference<>(context);
|
||||
mBitmapPool = Glide.get(context).getBitmapPool();
|
||||
mRadius = radius;
|
||||
mSampling = sampling;
|
||||
@ -91,7 +92,7 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(source, 0, 0, paint);
|
||||
|
||||
RenderScript rs = RenderScript.create(mContext);
|
||||
RenderScript rs = RenderScript.create(mContext.get());
|
||||
Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT);
|
||||
Allocation output = Allocation.createTyped(rs, input.getType());
|
||||
@ -102,6 +103,8 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
||||
blur.forEach(output);
|
||||
output.copyTo(bitmap);
|
||||
|
||||
source.recycle();
|
||||
resource.recycle();
|
||||
rs.destroy();
|
||||
|
||||
return BitmapResource.obtain(bitmap, mBitmapPool);
|
||||
|
Loading…
x
Reference in New Issue
Block a user