Question

I have a bitmap with width 720 and height 1020 I want to crop all four corners of the bitmap with the same value say 50. So 50 from top, left, bottom and right. Here is how I have tried this in my code

sourceImg = Bitmap.createBitmap(sourceImg, 50,
                            50, sourceImg.getWidth() - 50, sourceImg.getHeight() - 50);

The top and left seem to crop properly but the bottom and right do not.

Was it helpful?

Solution

You should use the calculation below. Width and height are decreased by corner value (half from each side).

sourceImg = Bitmap.createBitmap(sourceImg, 
    corner/2, 
    corner/2, 
    sourceImg.getWidth() - corner, 
    sourceImg.getHeight() - corner);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top