javax.imageio package dies reading PNG file

R

Robert Metzger

I am unable to get PNG reading to work using the javax.imageio.ImageIO package.
I'm using PNG because ImageIO doesn't have a GIF writer
(I need to both read and write) and the JPEG writer blurs
my pictures in very ugly ways.

Here's my code:

File iconFile= null;
BufferedImage image= null;
try {
iconFile= new File(PATH_TO_IMAGE);
image= ImageIO.read(iconFile); // <<< ERROR OCCURS HERE
} catch (IOException e ) {
}

Graphics2D gfx= image.createGraphics();
gfx.setFont(new Font("Helvetica", Font.PLAIN, 10));
gfx.setColor(new Color(255,255,255));

int offset= // some integer
gfx.drawString("Test",offset,48);

try {
ImageIO.write(image, "png", iconFile);
} catch (IOException e ) {
}

Here's the error occuring in the ImageIO package

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: LUT has improper length!
at javax.imageio.ImageTypeSpecifier$Indexed.<init>(Unknown Source)
at javax.imageio.ImageTypeSpecifier.createIndexed(Unknown Source)
at com.sun.imageio.plugins.png.PNGImageReader.getImageTypes(Unknown Source)
at com.sun.imageio.plugins.png.PNGImageReader.readImage(Unknown Source)
at com.sun.imageio.plugins.png.PNGImageReader.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)

The original PNG file was created by PaintShopPro.
Mozilla Firefox and Internet Exploder have no problems displaying it.

Any suggestions on how to read and write small graphic files (60x60 images)
would be greatly appreciated.
 
A

Andrey Kuznetsov

Robert,
I am unable to get PNG reading to work using the javax.imageio.ImageIO
package.
I'm using PNG because ImageIO doesn't have a GIF writer
(I need to both read and write) and the JPEG writer blurs
my pictures in very ugly ways.

you can find many libraries to read and write images here:
http://www.geocities.com/marcoschmidt.geo/java-image-coding.html


You can also try Imagero Reader: http://reader.imagero.com

Note: next version of Imagero Reader will include possibility to manipulate
JPEG images without quality loss.
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:
LUT has improper length!
at javax.imageio.ImageTypeSpecifier$Indexed.<init>(Unknown Source)
at javax.imageio.ImageTypeSpecifier.createIndexed(Unknown Source)
at com.sun.imageio.plugins.png.PNGImageReader.getImageTypes(Unknown
Source)
at com.sun.imageio.plugins.png.PNGImageReader.readImage(Unknown
Source)
at com.sun.imageio.plugins.png.PNGImageReader.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)

if you send me sample image I can try to investigate this problem.
my email can be found here: http://reader.imagero.com/mailto.php

Regards

Andrei
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top