0

I am trying to take the screenshot of a view using canvas api and noe I want to ignore a variable area and keep the rest of image. I have the coordinates (x(left),y(top) and (areatoignore width), (areatoignore height) ) of the variable area that I wanted to ignore while taking screenshot.How can I do that???

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
        view.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);

I am trying to modify the canvas after capturing as shown below but it does give the desired image.

canvas.clipRect(rectangle, Region.Op.DIFFERENCE);
canvas.save(); 

rectangle has the coordinates I want to ignore.

Galileo123
  • 185
  • 4
  • 17
  • This might answer your question: http://stackoverflow.com/a/9805831/4012979 with this http://stackoverflow.com/q/15789049/4012979 – Preston Garno Mar 11 '17 at 00:34
  • it will give the bitmap of the rectangle formed by coordinates. where as I want to remove that rectangle and get rest of image . like this http://www.screencast.com/t/iZlJ0cCDrIH – Galileo123 Mar 11 '17 at 01:22
  • That should still be possible - simply follow the first solution I linked and pass that method the View *or group of views i.e. LinearLayout, RelativeLayout, et al.* that contains the area you want to capture. Otherwise, follow the directions in the second link I posted and manually calculate the size of the cropped BufferedImage by subtracting the dimensions of the views you want to take out, then write it to the new BufferedImage with the new dimensions. The second solution is very time consuming, so I recommend figuring out the first one. – Preston Garno Mar 11 '17 at 01:28
  • Tried but it doesn't remove the rectangle from the image. Started following this http://stackoverflow.com/a/5432782/4619138 as the problem narrated is to remove a selected portion from bitmap. What I did is right here [https://www.screencast.com/t/hO33wBHc] but it doesn't give me the image without rectangle rather crop the rectangle and copy it to bitmap as shown here [https://www.screencast.com/t/uekl9MZVex8U ] – Galileo123 Mar 12 '17 at 01:13
  • 1
    seems to be working after I saved the canvas. here's what I did - `Canvas canvas = new Canvas(bitmap); Paint p = new Paint(); p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN)); activity.getWindow().getDecorView().draw(canvas); canvas.drawRect(hole,p); canvas.save();` – Galileo123 Mar 12 '17 at 02:21
  • nice! After looking into it briefly, I realized that the javax isn't even in the Android SDK, which is the package containing BufferedImage. Sorry if I sent you down the wrong path! Sometimes the lines bet blurred between JDK and the droid SDK – Preston Garno Mar 12 '17 at 05:39

0 Answers0