开发者

Manipulating PNGs in Java

开发者 https://www.devze.com 2022-12-26 13:39 出处:网络
Is there an 开发者_如何学Goeasy 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

Is there an 开发者_如何学Goeasy 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消