Forums Register Login

Problem while reading PNG image through ImageIO API

+Pie Number of slices to send: Send
Hi,

I am using the commons-fileupload API to upload images.

I first write the image to disk and then load it via ImageIO.read(new FileInputStream("my.png")) it works fine for some PNG images but for some PNG image it gives me error like.

javax.imageio.IIOException: Error reading PNG image data
at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1291)
at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1560)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1326)
at com.asite.imageio.ImageIOTest.readImage(ImageIOTest.java:45)
at com.asite.imageio.ImageIOTest.main(ImageIOTest.java:27)
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:223)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.DataInputStream.readFully(DataInputStream.java:178)
at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:1075)
at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1179)
at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1284)
... 5 more

Here is the code which i wrote to read image

BufferedImage image =ImageIO.read(new FileInputStream("abc.png"));
int width = image.getWidth();
int height = image.getHeight();
System.out.println("width : "+width+"\nheight : "+height);



+Pie Number of slices to send: Send
Firstly, have you made sure that after the upload, the files are bit-for-bit identical copies of the original files?

Secondly, be aware that web apps do not work well (or at all) with relative file paths (like "abc.png"); you should switch to using absolute paths (maybe by including the web app context root).
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 6974 times.
Similar Threads
Serialization/Deserialization a picture
changing colors
ImageIO.read return null
Issues With .PNG file
Image width & height return negative
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:12:33.