Is there an easy way to manipulate PNGs in Java? I know I can read into a BufferedImage and write that back out, but I need to add clear pixels around the edge of an image. Is there an easy way to do this?
Other people were useful, and you were not. -1
Stefan Kendall
2010-04-13 22:35:45
+1
A:
A quick solution would be to use the setRGB()
method to directly set RGBA values.
ilikeorangutans
2010-04-13 20:37:38
+3
A:
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.
camickr
2010-04-13 20:43:27
Notice that this is totally unrelated to the particular format of the image (PNG or whatever).
leonbloy
2010-04-14 16:08:01