javaandroid删除一个矩形并绘制图像的其余部分
我正试图从位图中裁剪出一个矩形,并在画布上绘制图像的其余部分。目前为止,我无法实现。请您帮助我好吗?守则如下—javaandroid删除一个矩形并绘制图像的其余部分,java,android,android-bitmap,Java,Android,Android Bitmap,我正试图从位图中裁剪出一个矩形,并在画布上绘制图像的其余部分。目前为止,我无法实现。请您帮助我好吗?守则如下— 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 rem
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
?????????
为了从活动位图中删除矩形部分,我们可以使用以下代码-
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();
您可以手动计算矩形坐标或提供您的矩形坐标。我通过了视图并使用了以下内容-
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;
其
创建位图(位图源,int x,int y,int width,int height)
和非创建位图(位图源,int x,int y,int right,int bottom)
,您所说的“我想得到剩下的画布”
?我的意思是createBitmap(位图源,int x,int y,int width,int height)给我一个裁剪过的图像(从x开始的矩形,y有我指定的宽度和高度)其中,我想要的是保留此处显示的剩余图像,因此使用Canvas
api从原始Bitmap
中删除/清除任何区域,我使用Canvas api获得了整个屏幕,然后获得了我想要从画布中删除的区域的坐标,并希望获得我在屏幕屏幕中给出的图像n cast.这是我从图像中删除矩形所做的,但无法获得所需的结果screencast.com/t/iZlJ0cCDrIH.而这就是我得到的。有什么建议吗??