mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-10 00:24:36 +08:00
setCanvasBitmapDensity (#147)
This commit is contained in:
parent
783d69c579
commit
e16eda6af1
@ -58,8 +58,12 @@ public abstract class BitmapTransformation implements Transformation<Bitmap> {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
|
||||
@NonNull Bitmap toTransform, int outWidth, int outHeight);
|
||||
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);
|
||||
|
||||
@Override
|
||||
public abstract void updateDiskCacheKey(@NonNull MessageDigest messageDigest);
|
||||
|
@ -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,11 +51,13 @@ public class ColorFilterTransformation extends BitmapTransformation {
|
||||
toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
|
||||
Bitmap bitmap = pool.get(width, height, config);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
@ -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,13 +68,15 @@ public class RoundedCornersTransformation extends BitmapTransformation {
|
||||
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setHasAlpha(true);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||
drawRoundRect(canvas, paint, width, height);
|
||||
return bitmap;
|
||||
}
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||
drawRoundRect(canvas, paint, width, height);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) {
|
||||
float right = width - margin;
|
||||
|
@ -67,11 +67,13 @@ public class SupportRSBlurTransformation extends BitmapTransformation {
|
||||
|
||||
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
setCanvasBitmapDensity(toTransform, bitmap);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user