ImageIO have problem of reading PNG?

C

carfield

I get the following exception, do I need another library to read PNG?

=====File=====

/var/www/html/meaningful/wise/Life_is_pain.png

=====StackTrace=====

java.lang.IllegalArgumentException: Unknown image type 0
at java.awt.image.BufferedImage.<init>(BufferedImage.java:492)
at hk.com.carfield.util.ImageUtil.scaleImage(ImageUtil.java:48)
at hk.com.carfield.item.FileItem.getThumbnail(FileItem.java:47)
 
S

Simon Shearn

I get the following exception, do I need another library to read PNG?

=====File=====

/var/www/html/meaningful/wise/Life_is_pain.png

=====StackTrace=====

java.lang.IllegalArgumentException: Unknown image type 0
at java.awt.image.BufferedImage.<init>(BufferedImage.java:492)
at hk.com.carfield.util.ImageUtil.scaleImage(ImageUtil.java:48)
at hk.com.carfield.item.FileItem.getThumbnail(FileItem.java:47)
I use ImageIO to read PNGs with no problems. Here's a code fragment that I
find works:

package ImageTools;
import java.util.*;
import java.awt.image.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.*;

class PNGToJPEG {

public void PNGToJPEG() {
}

public void convert(String inFileDir,
String inFileName,
String outFileDir,
String outFileName) {
try {
BufferedImage bimg = ImageIO.read(new File(inFileDir + "image.png"));
// more code here ...
} catch (Exception e) {
System.out.println(e.toString());
}
}
}

Regards,

Simon
 
C

Carfield Yim

Thx, actually I try to create a thumbnail of PNG using

BufferedImage image = new BufferedImage(width, height, type);

And I get the type from

ImageIO.read(new File("image.png")).getType()

Which java will return CUSTOM_TYPE for png, but I don't notic that
before... Now I change it to a predefine type and all problem solved.
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top