android paint 边框,android – 使用边框(Paint)在画布上的当前剪辑上绘制位图

我正在通过编写游戏来学习

Android,并且对图形API有疑问.

我想将图像绘制为路径的形状,然后在路径上添加边框.我能够使用Path剪切图像,但无法找到在其上添加边框的方法.我虽然很简单,因为API支持Canvas.draw *方法上的Paint对象.

更新

在原始问题中,我的路径包含两个矩形,@ christopher-souvey正确回答.但是,在处理添加一个clipPath()方法时,我遇到了另一个问题.

我通过在Path中添加一个圆来更新以前的代码.这是我的新代码:

Bitmap srcImage = BitmapFactory.decodeStream(getAssets().open("panda.jpg"));

Bitmap bitmapResult = Bitmap.createBitmap(srcImage.getWidth(), srcImage.getHeight(), Bitmap.Config.ARGB_8888);

Path path = new Path();

// This is my border

Paint paint = new Paint();

paint.setStyle(Style.STROKE);

paint.setColor(Color.RED);

paint.setStrokeWidth(2);

paint.setAntiAlias(true);

Canvas canvas = new Canvas(bitmapResult);

// Overlay two rectangles

path.addRect(10, 10, 70, 70, Path.Direction.CCW);

path.addRect(40, 40, 120, 120, Path.Direction.CCW);

canvas.drawPath(path , paint);

canvas.clipPath(path, Region.Op.INTERSECT);

path.reset();

path.addCircle(40, 80, 20, Path.Direction.CCW);

canvas.drawPath(path , paint);

canvas.clipPath(path, Region.Op.DIFFERENCE);

// The image is drawn within the area of two rectangles and a circle

// Although I suppose that puting Paint object into drawBitmap() method will add a red border on result image but it doesn't work

canvas.drawBitmap(srcImage, 0, 0, paint);

((ImageView)this.findViewById(R.id.imageView1)).setImageBitmap(bitmapResult);

我能错过什么让它起作用吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值