1
我想要使用下面的代碼四捨五入角落的位圖。問題是無論我如何將油漆的顏色設置爲Color.TRANSPARENT
,它總是黑色的。我如何實際上剪輯位圖的角落,而不僅僅是他們黑色?位圖與圓角&透明bg
謝謝!
public static Bitmap roundCorners(Bitmap src, int radius) {
//Create a *mutable* location, and a canvas to draw into it
int width = src.getWidth();
int height = src.getHeight();
Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
RectF rect = new RectF(0, 0, width, height);
Shader bitmapShader = new BitmapShader(src, TileMode.CLAMP, TileMode.CLAMP);
paint.setColor(0xFF000000);
paint.setShader(bitmapShader);
canvas.drawRoundRect(rect, radius, radius, paint);
return result;
}
我更新了代碼以使用您的方法,請參閱上文。同樣的問題,返回的位圖上的黑色背景仍然出現... – bitpshr
然後,它聽起來像你的位圖沒有清除。嘗試先執行bitmap.eraseColor(0)。 –