1. In many cases, we want to display the picture resources, need to display his resources as rounded, sample source code is as follows:
Public StaticBitmap Getroundedcornerbitmap (Bitmap Bitmap,floatroundpx) {Bitmap Output=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap. GetHeight (), config.argb_8888); Canvas Canvas=NewCanvas (output); Final intcolor = 0xff424242; FinalPaint paint =NewPaint (); FinalRect rect =NewRect (0, 0, Bitmap.getwidth (), Bitmap.getheight ()); FinalRECTF RECTF =NewRECTF (rect); Paint.setantialias (true); Canvas.drawargb (0, 0, 0, 0); Paint.setcolor (color); Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint); Paint.setxfermode (NewPorterduffxfermode (mode.src_in)); Canvas.drawbitmap (Bitmap, rect, rect, paint); returnoutput; }
Note: Bitmap is a picture resource; roundpx angle value float;
2. Get a picture of the circular resource.
Public StaticBitmap Getovalbitmap (Bitmap Bitmap) {Bitmap output=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap. GetHeight (), config.argb_8888); Canvas Canvas=NewCanvas (output); Final intcolor = 0xff424242; FinalPaint paint =NewPaint (); FinalRect rect =NewRect (0, 0, Bitmap.getwidth (), Bitmap.getheight ()); FinalRECTF RECTF =NewRECTF (rect); Paint.setantialias (true); Canvas.drawargb (0, 0, 0, 0); Paint.setcolor (color); Canvas.drawoval (RECTF, paint); Paint.setxfermode (NewPorterduffxfermode (mode.src_in)); Canvas.drawbitmap (Bitmap, rect, rect, paint); returnoutput; }
Note: The above code is tested and practical, copy can be used, if there is a problem, please leave a message to talk;