怎么用canvas在bitmap上画个边框?
我需要给Bitmap搞个圆角,然后再添加个边框给它,下面的代码是弄圆角的,但是不知道怎么用canvas给bitmap添加边框,anyideas?Bitmapoutput=...
我需要给Bitmap搞个圆角,然后再添加个边框给它,下面的代码是弄圆角的,但是不知道怎么用canvas给bitmap添加边框,any ideas?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); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, 20.0f, 20.0f, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output;
展开
3个回答
2013-08-30
展开全部
一般都是使用path把canvas剪切成一个圆角矩形的,然后再绘制边框和图片apidemo里面有些例子可以参考
展开全部
一般都是使用path把canvas剪切成一个圆角矩形的,
然后再绘制边框和图片apidemo里面有些例子可以参考
然后再绘制边框和图片apidemo里面有些例子可以参考
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Bitmapoutput=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);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, 20.0f, 20.0f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
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);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, 20.0f, 20.0f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询