我遇到了一个问题,我想将BufferedImage
转换为Shape
对象并排除所有透明像素。
我提出的算法非常糟糕,但有效。我想知道是否有人知道更有效的方法来获得相同的结果。这就是我现在所拥有的:
// O(n^2)
Area a = new Area();
Rectangle r = new Rectangle();
r.setSize(1,1);
for(int x = 0; x < image.getWidth(); x++)
for(int y = 0; y < image.getHeight(); y++)
if(image.getRGB(x,y) >>> 24 > 0){
r.setLocation(x,y);
a.add(new Area(r));
}
return a;