Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. }
  2. public class BorderTransformation2 extends com.bumptech.glide.load.resource.bitmap.BitmapTransformation {
  3. private float strokeWidth;
  4. private int strokeColor;
  5. public BorderTransformation2(Context context, float strokeWidth, int strokeColor) {
  6. super(context);
  7. this.strokeWidth = strokeWidth;
  8. this.strokeColor = strokeColor;
  9. }
  10. @Override
  11. protected Bitmap transform(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool pool, Bitmap bmp, int outWidth, int outHeight) {
  12. Bitmap sbmp;
  13. int radius = bmp.getWidth();
  14. if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
  15. float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
  16. float factor = smallest / radius;
  17. sbmp = Bitmap.createScaledBitmap(bmp, (int)(bmp.getWidth() / factor), (int)(bmp.getHeight() / factor), false);
  18. } else {
  19. sbmp = bmp;
  20. }
  21. Bitmap output = Bitmap.createBitmap(radius, radius, Bitmap.Config.ARGB_8888);
  22. Canvas canvas = new Canvas(output);
  23. final int color = 0xffa19774;
  24. final Paint paint = new Paint();
  25. final Paint stroke = new Paint();
  26. final Rect rect = new Rect(0, 0, radius, radius);
  27. paint.setAntiAlias(true);
  28. stroke.setAntiAlias(true);
  29. paint.setFilterBitmap(true);
  30. stroke.setFilterBitmap(true);
  31. paint.setDither(true);
  32. stroke.setDither(true);
  33. canvas.drawARGB(0, 0, 0, 0);
  34. paint.setColor(Color.RED);
  35. stroke.setColor(strokeColor); //border color stroke.setStyle(Paint.Style.STROKE); stroke.setStrokeWidth(strokeWidth);//border width
  36. canvas.drawCircle(radius / 2 + 0.7f,
  37. radius / 2 + 0.7f, radius / 2 + 0.1f, paint);
  38. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
  39. canvas.drawBitmap(sbmp, rect, rect, paint);
  40. canvas.drawCircle(radius / 2 + 0.7f,
  41. radius / 2 + 0.7f, radius / 2 - stroke.getStrokeWidth()/2 +0.1f, stroke);
  42. return output;
  43. }
  44. @Override
  45. public String getId() {
  46. return this.getClass().getName();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement