我用canavas 绘制的圆角矩形 圆角处怎么是黑色啊 怎么改成透明 这与画笔有关系么
这是效果图(圆角处有黑底而不是透明的)
Paint p = new Paint();
Bitmap bt=BitmapFactory.decodeResource(getResources(), R.drawable.creed);
Bitmap bmp=Bitmap.createScaledBitmap(bt, this.getWidth(), this.getHeight(),true);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 12;
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(bmp, rect, rect, paint); //绘制圆角背景图片
canvas.drawText(statuscontent1, posx,
nowpos1, p);
canvas.drawText(statuscontent2,
nowpos2, posy + dis, p); //绘制文字
[解决办法]
/**
*
* @param bitmap 待绘制的图片
* @param roundPx 表示绘制的矩形的四个角的圆的程度
* @return 绘制好的圆角图片
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
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);
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;
}
我的貌似没这种问题啊,你试试