5

Hi i am working on android application to detect page number using camera preview. After I received frame I draw a rectangle on surface view Using Canvas and I want to crop the rectangle area to put it in a bitmap, so please how can I do it ?as shown here

Kathir
  • 6,136
  • 8
  • 36
  • 67
Adnan KA
  • 99
  • 1
  • 2
  • 5

1 Answers1

22

If you have the bitmap of the frame, you can use

Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, rectanglePositionX, rectanglePositionY, rectangleWidth, rectangleHeight);

Assuming you know where your rectangle is positioned and its dimensions.

Bajji
  • 2,243
  • 2
  • 22
  • 35
  • i draw the rectangle by touch screen using **onTouch** so is it rectanglePositionX and rectanglePositionY same event.getX() and event.getY()? – Adnan KA Jul 27 '15 at 22:14
  • So in that case you should probably store the event.getX() and event.getY() some where and use those to crop the image ? – Bajji Jul 27 '15 at 22:24
  • cropping with wrong x and width, y and height seems fine. – Vishnuvardhan Feb 21 '22 at 10:00
  • Hello @Vishnuvardhan, did you solved that wrong x-positions while cropping? i to have same issue. If yes, can you please explain your solution? – Raj Nov 22 '22 at 18:18