Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- }
- public class BorderTransformation2 extends com.bumptech.glide.load.resource.bitmap.BitmapTransformation {
- private float strokeWidth;
- private int strokeColor;
- public BorderTransformation2(Context context, float strokeWidth, int strokeColor) {
- super(context);
- this.strokeWidth = strokeWidth;
- this.strokeColor = strokeColor;
- }
- @Override
- protected Bitmap transform(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool pool, Bitmap bmp, int outWidth, int outHeight) {
- Bitmap sbmp;
- int radius = bmp.getWidth();
- if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
- float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
- float factor = smallest / radius;
- sbmp = Bitmap.createScaledBitmap(bmp, (int)(bmp.getWidth() / factor), (int)(bmp.getHeight() / factor), false);
- } else {
- sbmp = bmp;
- }
- Bitmap output = Bitmap.createBitmap(radius, radius, Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(output);
- final int color = 0xffa19774;
- final Paint paint = new Paint();
- final Paint stroke = new Paint();
- final Rect rect = new Rect(0, 0, radius, radius);
- paint.setAntiAlias(true);
- stroke.setAntiAlias(true);
- paint.setFilterBitmap(true);
- stroke.setFilterBitmap(true);
- paint.setDither(true);
- stroke.setDither(true);
- canvas.drawARGB(0, 0, 0, 0);
- paint.setColor(Color.RED);
- stroke.setColor(strokeColor); //border color stroke.setStyle(Paint.Style.STROKE); stroke.setStrokeWidth(strokeWidth);//border width
- canvas.drawCircle(radius / 2 + 0.7f,
- radius / 2 + 0.7f, radius / 2 + 0.1f, paint);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- canvas.drawBitmap(sbmp, rect, rect, paint);
- canvas.drawCircle(radius / 2 + 0.7f,
- radius / 2 + 0.7f, radius / 2 - stroke.getStrokeWidth()/2 +0.1f, stroke);
- return output;
- }
- @Override
- public String getId() {
- return this.getClass().getName();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement