質問

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.

役に立ちましたか?

解決

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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top