(Attachments to this list is not allowed?)

Find a test program inline below, which exposes problems in the Image I/O
libraries.


Running it against the following two TIFFs will in one case work, and not in
the other;

    http://www.apache.org/~niclas/401505.tif

    http://www.apache.org/~niclas/773805.tif

Run the application by;
   java -cp . ImageTest  <filename>  <out-format>


These are the results;

[EMAIL PROTECTED]:~$ java -cp . ImageTest 773805.tif png
Content-type: image/png

[EMAIL PROTECTED]:~$ java -cp . ImageTest 401505.tif png
Exception in thread "main" java.lang.Exception: Unable to find a ImageWriter:
png
        at ImageTest.main(ImageTest.java:30)


Anyone who have some in-depth knowledge give me a clue what is happening.


Cheers and TIA
Niclas Hedhman


System used;
  Linux 2.6.8-1-686
  JDK 1.4.2_06, Hotspot Client
  jai_imageio-1_0_01-lib-linux-i586-jdk.bin

-------------------------------------------------------


import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.imageio.spi.*;
import javax.imageio.stream.*;

public class ImageTest
{
    public static void main( String[] args )
        throws Exception
    {
        String format = args[1];
        FileInputStream fis = new FileInputStream( args[0] );
        BufferedInputStream in = new BufferedInputStream( fis );
        BufferedImage image = ImageIO.read( in );
        if( image == null )
            throw new Exception( "Unable to decode the InputStream. Possibly
an unknown format." );
        in.close();

        ImageTypeSpecifier its =
ImageTypeSpecifier.createFromRenderedImage( image );
        Iterator writers = ImageIO.getImageWriters( its, format );
        ImageWriter writer = null;
        if( writers.hasNext() )
        {
            writer = (ImageWriter) writers.next();
        }
        if( writer == null )
            throw new Exception( "Unable to find a ImageWriter: " + format );

        ImageWriterSpi spi = writer.getOriginatingProvider();
        String[] mimetypes = spi.getMIMETypes();
        System.out.println( "Content-type: " + mimetypes[0] );
        FileOutputStream fos = new FileOutputStream( args[0] + "-conv." +
format );
        BufferedOutputStream out = new BufferedOutputStream( fos );

        ImageOutputStream output = ImageIO.createImageOutputStream( out );
        try
        {
            writer.setOutput( output );
            writer.write( image );
        } finally
        {
            writer.dispose();
            output.close();
            out.flush();
        }
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to