- public static Bitmap getRoundCornerImage(Bitmap bitmap, int roundPixels)
- {
- //创建一个和原始图片一样大小位图
- Bitmap roundConcerImage = Bitmap.createBitmap(bitmap.getWidth(),
- bitmap.getHeight(), Config.ARGB_8888);
- //创建带有位图roundConcerImage的画布
- Canvas canvas = new Canvas(roundConcerImage);
- //创建画笔
- Paint paint = new Paint();
- //创建一个和原始图片一样大小的矩形
- Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
- RectF rectF = new RectF(rect);
- // 去锯齿
- paint.setAntiAlias(true);
- //画一个和原始图片一样大小的圆角矩形
- canvas.drawRoundRect(rectF, roundPixels, roundPixels, paint);
- //设置相交模式
- paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
- //把图片画到矩形去
- canvas.drawBitmap(bitmap, null, rect, paint);
- return roundConcerImage;
- }
图片圆角效果
时间: 2024-10-26 06:59:15