[英]Java android remove a rectangle and draw the rest of the image
I am trying to crop a rectangle from a bitmap and draw the rest of the image on a canvas.Could achieve that so far.Could you please help? 我正在尝试从位图裁剪一个矩形并将其余图像绘制在画布上,到目前为止可以做到这一点,请您帮忙吗? Code is as below- 代码如下-
1. //draw activity on the canvas. this returns a bitmap used in Bitmap.createBitmap(3)
activity.getWindow().getDecorView().draw(canvas);
2. //get the coordinates that I want to clip.
Rect removeImage = new rect(coordinates of rect portion)
3. //check that I can get the cropped image
Bitmap croppedImage = Bitmap.createBitmap(bitmap, leftCrop, topCrop, rightCrop, bottomCrop);
4. //Now I want to get the remaining canvas and remove the rectangular region
?????????
In order to remove a rectangular portion from the bitmap of an activity we can use following code- 为了从活动的位图中删除矩形部分,我们可以使用以下代码-
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint p = new Paint();
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
activity.getWindow().getDecorView().draw(canvas);
canvas.drawRect(rect,p);
canvas.save();
You can manually calculate the rectangle coordinates or supply yours. 您可以手动计算矩形坐标或提供您的矩形坐标。 I passed the view and used the following - 我通过了视图并使用了以下内容-
Rect coordinates = new Rect();
int[] xyLocation = new int[2];
if (view == null) {
return coordinates;
}
view.getLocationOnScreen(xyLocation);
coordinates.left = xyLocation[0];
coordinates.top = xyLocation[1];
coordinates.right = coordinates.left + view.getWidth();
coordinates.bottom = corrdinates.top + view.getHeight();
return coordinates;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.