Customer login  |   Contact us
Home Company Products Support Purchase
Forum Home » ObjectPlanet Developer forum

Topic: PngEncoder
Replies: 4   Pages: 1   Last Post: Oct 22, 2008 10:23 AM by: mikaelgrev


Back to Topic List Back to Topic List
Replies: 4   Pages: 1  
mikaelgrev

Posts: 4
Registered: Apr 17, 2008
PngEncoder
Posted: Apr 17, 2008 10:06 PM
  Reply

Hello,

First, thanks for a very fast PNG encoder.

There is a bug in PngEncoder for transparency. Basically the color for translucent pixels are wrong. The following code will create an image that when returned has a gray outer ring. ImageIO creates the correct image. I have used the TRUECOLOR_ALPHA setting for PngEncoder.


g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

g2.setComposite(AlphaComposite.Src);

g2.setColor(new Color(255, 255, 255, 0));
g2.fillRect(0, 0, width, height);

g2.setComposite(AlphaComposite.SrcOver);

g2.setColor(Color.WHITE);
g2.fillOval(0, 0, width, height);


The code paints into a translucent BufferedImage.

Cheers,
Mikael Grev
MiG InfoCom AB

mikaelgrev

Posts: 4
Registered: Apr 17, 2008
Re: PngEncoder
Posted: Apr 17, 2008 10:16 PM
  Reply

Btw, if you don't understand what I mean please let me know and I will whip up a complete example with all the code to reproduce the erratic image.
I will only do that if you are interested in fixing it though.

Cheers,
Mikael

Philipp Kolibaba

Posts: 454
Registered: Jun 20, 2002
Re: PngEncoder
Posted: Apr 23, 2008 2:46 PM
  Reply

We are Please send the complete example.

mikaelgrev

Posts: 4
Registered: Apr 17, 2008
Re: PngEncoder
Posted: May 19, 2008 8:45 PM
  Reply

Hello again,

Sorry for the delay, it was crazy around JavaOne..


import com.objectplanet.image.PngEncoder;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.FileOutputStream;

public class PngTest
{
private final static PngEncoder PNG_ENCODER = new PngEncoder(PngEncoder.COLOR_TRUECOLOR_ALPHA);

public static void main(String[] args)
{
BufferedImage img = new BufferedImage(10, 10, BufferedImage.TRANSLUCENT);

Graphics2D g2 = (Graphics2D) img.getGraphics();

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

g2.setComposite(AlphaComposite.Src);

g2.setColor(new Color(255, 255, 255, 0));
g2.fillRect(0, 0, 10, 10);

g2.setComposite(AlphaComposite.SrcOver);

g2.setColor(Color.WHITE);
g2.fillOval(0, 0, 10, 10);

g2.dispose();

FileOutputStream fis = null;
try {
fis = new FileOutputStream("/test.png");
PNG_ENCODER.encode(img, fis); // Faster but has problems with gray outline with transparency
// ImageIO.write(img, "png", fis);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (fis != null)
try { fis.close(); } catch (IOException ex) {}
}
}
}



mikaelgrev

Posts: 4
Registered: Apr 17, 2008
Re: PngEncoder
Posted: Oct 22, 2008 10:23 AM
  Reply

Bump...



© 1998-2017 ObjectPlanet, Inc. Øvre Slottsgate 5, 0157 Oslo, Norway Tel (+47) 2233 3360 | Fax (+47) 2233 3361