Hi all,
       I am trying to convert a black and white tiff image to jpg/png. I am
reading tif image from binary file. First of all a 4kb file when written in
binary format expand to 57 kb :(. then when i try to convert this binary
file to jpeg format , the image is all blank. Please help. My sample code
is as below.

Regards,
Jatinder

 -------------Writing tiff to binary file.--------------


            FileSeekableStream stream = new FileSeekableStream(rawDataFile);

            stream.seek(start);

            stream.read(array,(int)0,(int)(end-start));

            ByteArraySeekableStream byteStream = new ByteArraySeekableStream
(array);

            img =  (RenderedImage)JAI.create("stream",byteStream);
            imageBuffer.put(img);


 --------------Converting binary tiff to jpg.---------------

        outRawData = new FileOutputStream(rawDataFile,true);

        // getting image from image buffer
        RenderedImage img = imageBuffer.get();
        RenderedImageAdapter ria = new RenderedImageAdapter(img);

        BufferedImage bi = ria.getAsBufferedImage();


        ImageEncoder encoder = null;
        com.sun.media.jai.codec.JPEGEncodeParam jpgParams = null;

        if("JPEG".equalsIgnoreCase(targetImageType)
|| "JPG".equalsIgnoreCase(targetImageType)){
                    jpgParams = new com.sun.media.jai.codec.JPEGEncodeParam
();
                    jpgParams.setQuality(jpgQuality);
                    encoder = ImageCodec.createImageEncoder
("JPEG",outRawData, jpgParams);
                    System.out.println("making jpg file");
                }

                encoder.encode(bi);
                outRawData.flush();

                fileLength = rawDataFile.length();

                if(fileLength == 0){
                    indexDataWriter.write(imageName+"|"+"0"+"|");
                }
                else{
                    indexDataWriter.write
(fileLength+"\n"+imageName+"|"+fileLength+"|");

                }
                indexDataWriter.flush();

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to