Search code examples
androidcanvasandroid-cameracropandroid-camera-intent

How can crop rectangle area?


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


Solution

  • 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.