有没有一种简单的方法可以在 Java 中操作 PNG?我知道我可以读入 BufferedImage 并将其写回,但我需要在图像边缘周围添加清晰的像素。是否有捷径可寻?
问问题
621 次
2 回答
5
Never tried it but you could try creating a buffered image at the appropriate size including the border you want around the image. So for a border of 5 pixels the code might be something like:
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.setColor( new Color(0, 0, 0, 0) );
g2d.fillRect(0, 0, width, height);
g2d.drawImage(image, 5, 5, null);
Or if you want to keep the image at its original size then you just use 4 fillRect(...) methods to overwrited the top/bottom/left/right edges of the image.
于 2010-04-13T20:43:27.010 回答
2
一个快速的解决方案是使用该setRGB()
方法直接设置 RGBA 值。
于 2010-04-13T20:37:38.677 回答