Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#18 png file reading problem

closed
nobody
None
5
2010-08-31
2010-08-31
jane g
No

Hi Jeremias,
I am new to barcode4j. I am using BarcodeServlet to generate barcode and read through URL as follows:

URL servletImageUrl = new URL(“/genbc?type=ean-13&msg=9400550606072&height=13&hrp=bottom&fmt=png&res=75&indicator=on”);
BufferedImage image = ImageIO.read(servletImageUrl);
File f = new File(\"/barcode4j/9400550606072.png”);
ImageIO.write(image,”png”, f);

I can make it work when output format is jpg, but I get the following exception when I change output format to png:
java.awt.image.RasterFormatException: IntegerComponentRasters must have ComponentSampleModel or SinglePixelPackedSampleModel
at sun.awt.image.ByteComponentRaster.<init>(ByteComponentRaster.java:197)
at sun.awt.image.ByteInterleavedRaster.<init>(ByteInterleavedRaster.java:192)
at sun.awt.image.ByteInterleavedRaster.<init>(ByteInterleavedRaster.java:114)
at java.awt.image.Raster.createPackedRaster(Raster.java:484)
at com.sun.imageio.plugins.png.PNGImageReader.createRaster(PNGImageReader.java:870)
at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:991)
at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1189)
at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1281)
at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1553)
at javax.imageio.ImageIO.read(ImageIO.java:1439)
at javax.imageio.ImageIO.read(ImageIO.java:1391)

I have tried on barcode4j-1 and barcode4j-2, and jdk1.5 and jdk1.6, and I get the same error. The box is Linux Fedora release 8.
Your help will be greatly appreciated.

Discussion

  • Hi Jane

    Hmm, I haven't been able to reproduce this. I can load the PNG generated by the servlet with Sun JDKs 1.4.2, 1.5.0 and 6.0 on Windows.

    My best guess is that you're actually using OpenJDK or IcedTea on Fedora but you didn't notice that. It's sometimes a bit tricky to have the right JDK running on a Unix. See:
    http://www.mail-archive.com/unix@lists.slimdevices.com/msg11124.html
    http://ubuntuforums.org/archive/index.php/t-762650.html

    It looks like the solution might be to make sure that you're really using the official Sun/Oracle JDK. HTH. Please re-open if that doesn't solve it.

     
    • status: open --> closed