代码片段(1)
[代码] [Java]代码
01 | //生成圆角图片 |
02 | public static Bitmap GetRoundedCornerBitmap(Bitmap bitmap) { |
03 | try { |
04 | Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), |
05 | bitmap.getHeight(), Config.ARGB_8888); |
06 | Canvas canvas = new Canvas(output); |
07 | final Paint paint = new Paint(); |
08 | final Rect rect = new Rect( 0 , 0 , bitmap.getWidth(), |
09 | bitmap.getHeight()); |
10 | final RectF rectF = new RectF( new Rect( 0 , 0 , bitmap.getWidth(), |
11 | bitmap.getHeight())); |
12 | final float roundPx = 14 ; |
13 | paint.setAntiAlias( true ); |
14 | canvas.drawARGB( 0 , 0 , 0 , 0 ); |
15 | paint.setColor(Color.BLACK); |
16 | canvas.drawRoundRect(rectF, roundPx, roundPx, paint); |
17 | paint.setXfermode( new PorterDuffXfermode(Mode.SRC_IN)); |
18 | |
19 | final Rect src = new Rect( 0 , 0 , bitmap.getWidth(), |
20 | bitmap.getHeight()); |
21 | |
22 | canvas.drawBitmap(bitmap, src, rect, paint); |
23 | return output; |
24 | } catch (Exception e) { |
25 | return bitmap; |
26 | } |
27 | } |