Note that there are some explanatory texts on larger screens.

plurals
  1. POError converting PNG to TIFF-Java
    primarykey
    data
    text
    <p>HI I am working on the following snippet which is supposed to convert my png file to tiff.</p> <pre><code> String fileName = "4848970_1"; // String fileName = "color"; String inFileType = ".PNG"; String outFileType = ".TIFF"; File fInputFile = new File("C:\\Users\\abc\\Downloads\\image2.png"); InputStream fis = new BufferedInputStream(new FileInputStream(fInputFile)); ImageReaderSpi spi = new PNMImageReaderSpi(); ImageReader reader = spi.createReaderInstance(); ImageInputStream iis = ImageIO.createImageInputStream(fis); reader.setInput(iis, true); BufferedImage bi = reader.read(0); int[] xi = bi.getSampleModel().getSampleSize(); for (int i : xi) { System.out.println("bitsize " + i); } ImageWriterSpi tiffspi = new TIFFImageWriterSpi(); TIFFImageWriter writer = (TIFFImageWriter) tiffspi.createWriterInstance(); // TIFFImageWriteParam param = (TIFFImageWriteParam) writer.getDefaultWriteParam(); TIFFImageWriteParam param = new TIFFImageWriteParam(Locale.US); String[] strings = param.getCompressionTypes(); for (String string : strings) { System.out.println(string); } //param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); //param.setCompressionType("LZW"); File fOutputFile = new File("C:\\Users\\abc\\Downloads\\" + fileName + outFileType); OutputStream fos = new BufferedOutputStream(new FileOutputStream(fOutputFile)); ImageOutputStream ios = ImageIO.createImageOutputStream(fos); writer.setOutput(ios); writer.write(null, new IIOImage(bi, null, null), param); ios.flush(); writer.dispose(); ios.close(); </code></pre> <p>But this gives me following error</p> <pre><code>Exception in thread "main" java.lang.RuntimeException: What in the stream isn't a PNM image. at com.sun.media.imageioimpl.plugins.pnm.PNMImageReader.readHeader(PNMImageReader.java:187) at com.sun.media.imageioimpl.plugins.pnm.PNMImageReader.read(PNMImageReader.java:301) at javax.imageio.ImageReader.read(Unknown Source) at com.imageconv.TiffImage.main(TiffImage.java:40) </code></pre> <p>Is it that its unable to read the PNG file or it recognises it as a non png file.Am I wrong anywhere?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload