Generally to do a circular picture, can only be based on the square can be achieved, otherwise it becomes an ellipse, the following say how to make a rectangular picture of a circular picture
Don't say much nonsense, no picture no truth, first on the map:
Original:
After turning into a positive circle:
The following code:
public static Bitmap Makeroundcorner (Bitmap Bitmap) {int width = bitmap.getwidth ();
int height = bitmap.getheight ();
int left = 0, top = 0, right = width, bottom = height;
float roundpx = HEIGHT/2;
if (width > height) {left = (width-height)/2;
top = 0;
right = left + height;
bottom = height;
else if (height > width) {left = 0;
top = (height-width)/2;
right = width;
Bottom = top + width;
ROUNDPX = WIDTH/2;
ZLOG.I (TAG, "PS:" + Left + "," + Top + "," + Right + "," + bottom);
Bitmap output = bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888);
Canvas Canvas = new Canvas (output);
int color = 0xff424242;
Paint Paint = new Paint ();
Rect Rect = new Rect (left, top, right, bottom);
RECTF RECTF = new RECTF (rect);
Paint.setantialias (TRUE);
Canvas.drawargb (0, 0, 0, 0);
Paint.setcolor (color);
Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint); Paint.setxfermode (New PorteRduffxfermode (PorterDuff.Mode.SRC_IN));
Canvas.drawbitmap (Bitmap, rect, rect, paint);
return output;
}
Here's another explanation:
Because the picture is rectangular, so the picture of the width and height of the image must be smaller than the other side, to generate a square on the smallest side as the benchmark, and then trim to the other side of the display range
As for the radius of the rounded corner is a square width of half, with CSS to know, draw a circle is very convenient Border-radius set to 50% on it, is a truth
Android's UI is so tedious.
Rectangle to draw a rounded corner code:
public static Bitmap Makeroundcorner (Bitmap Bitmap, int px)
{
int width = bitmap.getwidth ();
int height = bitmap.getheight ();
Bitmap output = bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888);
Canvas Canvas = new Canvas (output);
int color = 0xff424242;
Paint Paint = new Paint ();
Rect Rect = new Rect (0, 0, width, height);
RECTF RECTF = new RECTF (rect);
Paint.setantialias (true);
Canvas.drawargb (0, 0, 0, 0);
Paint.setcolor (color);
Canvas.drawroundrect (RECTF, px, px, paint);
Paint.setxfermode (New Porterduffxfermode (PorterDuff.Mode.SRC_IN));
Canvas.drawbitmap (Bitmap, rect, rect, paint);
return output;