简体   繁体   English

从各个角度均匀地裁剪位图

[英]Cropping a bitmap evenly from all corners

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. 我有一个宽度为720,高度为1020的位图,我想使用相同的值裁剪该位图的所有四个角,例如50。所以从顶部,左侧,底部和右侧分别为50。 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM