mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-08 07:24:05 +08:00
setCanvasBitmapDensity (#147)
This commit is contained in:
parent
783d69c579
commit
e16eda6af1
@ -58,6 +58,10 @@ public abstract class BitmapTransformation implements Transformation<Bitmap> {
|
||||
return result;
|
||||
}
|
||||
|
||||
void setCanvasBitmapDensity(@NonNull Bitmap toTransform, @NonNull Bitmap canvasBitmap) {
|
||||
canvasBitmap.setDensity(toTransform.getDensity());
|
||||
}
|
||||
|
||||
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight);
|
||||
|
||||
|
@ -64,6 +64,8 @@ public class BlurTransformation extends BitmapTransformation {
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
setCanvasBitmapDensity(toTransform,bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
|
@ -51,6 +51,8 @@ public class ColorFilterTransformation extends BitmapTransformation {
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
|
@ -76,6 +76,8 @@ public class CropTransformation extends BitmapTransformation {
|
||||
float top = getTop(scaledHeight);
|
||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||
|
||||
setCanvasBitmapDensity(toTransform,bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(toTransform, null, targetRect, null);
|
||||
|
||||
|
@ -45,6 +45,8 @@ public class GrayscaleTransformation extends BitmapTransformation {
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
setCanvasBitmapDensity(toTransform,bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
ColorMatrix saturation = new ColorMatrix();
|
||||
saturation.setSaturation(0f);
|
||||
|
@ -64,6 +64,8 @@ public class MaskTransformation extends BitmapTransformation {
|
||||
|
||||
Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
|
||||
|
||||
setCanvasBitmapDensity(toTransform,bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
mask.setBounds(0, 0, width, height);
|
||||
mask.draw(canvas);
|
||||
|
@ -68,6 +68,8 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
|
@ -67,6 +67,8 @@ public class SupportRSBlurTransformation extends BitmapTransformation {
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
|
Loading…
x
Reference in New Issue
Block a user