Login  Register

Re: ImageJ resizing PNG with no transparency loss - how to

Posted by Martin Asenov on May 04, 2011; 8:11am
URL: http://imagej.273.s1.nabble.com/ImageJ-resizing-PNG-with-no-transparency-loss-how-to-tp3683481p3683483.html




Hi, Jarek


Thanks for your output. As far as I understand, ImageJ does not currently
support resizing PNG images with no transparency loss, is this right?


Thank you,


Martin


----- Цитат от Jarek Sacha ([hidden email]), на
04.05.2011 в 04:55 -----   Martin:


Below is scaling that works with transparent image using standard Java
API (Groovy syntax).


Jarek
http://ij-plugins.sf.net/


------------------------------------------------------------------------


import java.awt.RenderingHints
import java.awt.image.BufferedImage
import javax.imageio.ImageIO


// Read image to scale
def src = ImageIO.read(new File("test/data/scala64.png"))


// Create scaled destination image with transparency (ARGB)
int destWidth = 32
int destHeight = 32
def dest = new BufferedImage(destWidth, destHeight,
BufferedImage.TYPE_INT_ARGB);


// Paint source image into the destination, scaling as needed
def graphics2D = dest.createGraphics()
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR)
graphics2D.drawImage(src, 0, 0, destWidth, destHeight, null)
graphics2D.dispose()


// Save destination image
ImageIO.write(dest, "PNG", new File("test/data/scala32.png"))


------------------------------------------------------------------------


On 5/3/2011 6:27 AM, Martin Asenov wrote:
   However, I tried to resize a PNG image with some transparency, and
unfortunately, the transparency got lost and replaced with the black color.