Changing Image as Rounded Corner

后端 未结 4 897
青春惊慌失措
青春惊慌失措 2020-12-17 03:34

I\'ve one listview with some items. In my listview i\'ve using custom adapter for displaying the items with images. My images in items are coming from JSON My i

4条回答
  •  醉酒成梦
    2020-12-17 03:38

    public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
                .getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
    
        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = pixels;
    
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
    
        return output;
    }
    

提交回复
热议问题