下面列出了怎么用com.bumptech.glide.load.resource.bitmap.TransformationUtils的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
Bitmap bitmap = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
setCanvasBitmapDensity(toTransform, bitmap);
Paint paint = new Paint();
paint.setColor(borderColor);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(borderSize);
paint.setAntiAlias(true);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(
outWidth / 2f,
outHeight / 2f,
Math.max(outWidth, outHeight) / 2f - borderSize / 2f,
paint
);
return bitmap;
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Log.d(TAG, String.format("Height: %d Width: %d", toTransform.getHeight(), toTransform.getWidth()));
if (toTransform.getHeight() >= toTransform.getWidth()){
// Perform fit center here on un-rotated image.
toTransform = TransformationUtils.fitCenter(toTransform, pool, outWidth, outHeight);
return toTransform;
}
// Fit center using largest side (width) for both to reduce computation for rotate
//noinspection SuspiciousNameCombination
toTransform = TransformationUtils.fitCenter(toTransform, pool, outWidth, outWidth);
return TransformationUtils.rotateImage(toTransform, 90);
}
private Bitmap centerCrop(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
final Bitmap toReuse = pool.get(outWidth, outHeight, getSafeConfig(toTransform));
final Bitmap transformed = TransformationUtils.centerCrop(toReuse, toTransform, outWidth, outHeight);
if (toReuse != null && toReuse != transformed && !pool.put(toReuse)) {
toReuse.recycle();
}
return transformed;
}
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight);
return blurBitmap(mContext, bitmap, 20, outWidth, outHeight);
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight);
return roundCrop(pool, bitmap);
}
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
return TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);
}
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
this.size = Math.max(outWidth, outHeight);
return TransformationUtils.centerCrop(pool, toTransform, size, size);
}
private Bitmap fitCenter(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return TransformationUtils.fitCenter(toTransform, pool, outWidth, outHeight);
}