将半透明的BufferedImage转换为Shape对象

时间:2012-05-13 02:21:20

标签: java graphics

我遇到了一个问题,我想将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;

0 个答案:

没有答案