2

I would like to draw a round bitmap (transparent square 50x50 with round colorfull picture by a radius 25 in a center) with smooth edges. How can I handle that? I tried this, but it doesn't work (edges aren't smooth):

Paint p =new Paint();
p.setFilterBitmap(true);
p.setAntiAlias(true);
canvas.drawBitmap(bitmap, x - (bitmap.getWidth() / 2), y - (bitmap.getWidth() / 2), p);
Lucas
  • 61
  • 7

1 Answers1

0

You can check below code and have to make some workaround

int w = bitmap.getWidth();                                          
int h = bitmap.getHeight();  

int radius = Math.min(h / 2, w / 2);                                
Bitmap output = Bitmap.createBitmap(w + 8, h + 8, Config.ARGB_8888);

Paint p = new Paint();                                              
p.setAntiAlias(true);                                               

Canvas c = new Canvas(output);                                      
c.drawARGB(0, 0, 0, 0);                                             
p.setStyle(Style.FILL);                                             

c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, p);                  

p.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));                 

c.drawBitmap(bitmap, 4, 4, p);                                      
p.setXfermode(null);                                                
p.setStyle(Style.STROKE);                                           
p.setColor(Color.WHITE);                                            
p.setStrokeWidth(3);                                                
c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, p);                  

return output; 

Source

Community
  • 1
  • 1
Krishna
  • 706
  • 5
  • 22