views:

56

answers:

3

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?

A: 

Unless you tell us more, no that's the easiest way

Pyrolistical
Other people were useful, and you were not. -1
Stefan Kendall
+1  A: 

A quick solution would be to use the setRGB() method to directly set RGBA values.

ilikeorangutans
+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
This is definitely the simple solution I was looking for.
Stefan Kendall
Notice that this is totally unrelated to the particular format of the image (PNG or whatever).
leonbloy