Вопрос

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