mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-07-01 13:52:44 +08:00
Use application context.
This commit is contained in:
parent
eef0be6b92
commit
c29df80ae9
@ -29,14 +29,13 @@ import com.bumptech.glide.load.Transformation;
|
|||||||
import com.bumptech.glide.load.engine.Resource;
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
public class BlurTransformation implements Transformation<Bitmap> {
|
public class BlurTransformation implements Transformation<Bitmap> {
|
||||||
|
|
||||||
private static int MAX_RADIUS = 25;
|
private static int MAX_RADIUS = 25;
|
||||||
private static int DEFAULT_DOWN_SAMPLING = 1;
|
private static int DEFAULT_DOWN_SAMPLING = 1;
|
||||||
|
|
||||||
private WeakReference<Context> mContext;
|
private Context mContext;
|
||||||
private BitmapPool mBitmapPool;
|
private BitmapPool mBitmapPool;
|
||||||
|
|
||||||
private int mRadius;
|
private int mRadius;
|
||||||
@ -59,14 +58,14 @@ public class BlurTransformation implements Transformation<Bitmap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
public BlurTransformation(Context context, BitmapPool pool, int radius, int sampling) {
|
||||||
mContext = new WeakReference<>(context);
|
mContext = context.getApplicationContext();
|
||||||
mBitmapPool = pool;
|
mBitmapPool = pool;
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mSampling = sampling;
|
mSampling = sampling;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlurTransformation(Context context, int radius, int sampling) {
|
public BlurTransformation(Context context, int radius, int sampling) {
|
||||||
mContext = new WeakReference<>(context);
|
mContext = context.getApplicationContext();
|
||||||
mBitmapPool = Glide.get(context).getBitmapPool();
|
mBitmapPool = Glide.get(context).getBitmapPool();
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mSampling = sampling;
|
mSampling = sampling;
|
||||||
@ -74,10 +73,6 @@ 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();
|
||||||
@ -96,7 +91,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(context);
|
RenderScript rs = RenderScript.create(mContext);
|
||||||
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());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user