views:

426

answers:

3

I have tried both lines of code below to no avail. The code works fine with jpg, or gif but turns the image pink if a png.

ImageIO.write(input, "jpg", profileFile);

RenderedOp op = JAI.create("filestore", input, pFileName, "jpeg");

Anyone else run into this problem? I haven't been able to find a solution.

A: 

I'm not sure if this is the right answer or not. But there is another post that suggest that the implementation of JPEG writting with an alpha channel is a bit screwy.

monksy
+1  A: 

You have duplicated your question. And there is answer about reported bug in Sun's library and workaround and link.

http://stackoverflow.com/questions/1830063/problem-converting-png-to-jpg-using-java-imageio-write/1830086#1830086

RocketSurgeon
A: 

I draw PNGs with the following code and do not run into a problem. It combines multiple PNG images into a single image. The images have transparency, and use bilinear transform for blending.

BufferedImage image = new BufferedImage(BOARD_SIZE, BOARD_SIZE, BufferedImage.TYPE_INT_ARGB); 
Graphics2D g2d = image.createGraphics();
AffineTransformOp transformOp = new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_BILINEAR);
g2d.drawImage(someOtherImage, transformOp, 0, 0);

When I finish the image, I write it to a response using the following code:

OutputStream responseStream = response.getOutputStream();
ImageIO.write(image, "PNG", responseStream);
Kaleb Brasee