3

使用 Java 成像我将如何找到图像的最小可视矩形。在这里,我认为 alpha/透明像素是不可见的。我想找到尺寸,以便我可以自动裁剪图像。我想以图像中立的方式做到这一点,但如果这是不可能的,那么 PNG。

4

1 回答 1

4

Assuming that you don't want to crop out even a single "viewable" pixel, I would use the following algorithm:

Scan the topmost horizontal line, iterating pixel by pixel. If no viewable pixels exist in that line, advance to the second topmost line and so on until you find a line with a viewable pixel.

Do the same for the bottom, advancing upwards, and also for the sides, advancing inwards.

After all 4 steps, you will have how many lines of pixels you can trim from each side of the image.

于 2012-06-11T00:44:14.897 回答