I am using a text view. It has one image as background. How do I programmatically round this image's corner?
Convert your image to bitmap and then convert that bitmap with rounded corners bitmap. Finally apply that bitmap to your textview background. The below code is for convert bitmap to rounded bitmap image.
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,int roundPixelSize) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
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 = roundPixelSize;
paint.setAntiAlias(true);
canvas.drawRoundRect(rectF,roundPx,roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With