Skip to main content

Retrive the embedded Thumbnail from the Tiff file

5 replies [Last post]
makwanasonal
Offline
Joined: 2006-10-02

Hello,
can any one tell me how to retrieve the embedded thumbnail from TIFF file??

if anyone know this then please let me know about this solution.

Sonal.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
robert engels

Did you even read the Javadoc? Look at the Javadoc for the ImageIO
class.

On Dec 15, 2006, at 1:27 AM, jai-imageio@javadesktop.org wrote:

> Hello,
> can any one tell me how to retrieve the embedded thumbnail from
> TIFF file??
>
> if anyone know this then please let me know about this solution.
>
> Sonal.
> [Message sent by forum member 'makwanasonal' (makwanasonal)]
>
> http://forums.java.net/jive/thread.jspa?messageID=186749
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

makwanasonal
Offline
Joined: 2006-10-02

i go through it.my code works fine with jpeg format but when i am applying it with the "TIFF" file format it fire the execption.

javax.imageio.IIOException: Couldn't seek!
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.locateImage(TIFFImageReader.java:217)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getNumImages(TIFFImageReader.java:240)
at ThumbnailView.(ThumbnailView.java:67)
at ThumbnailView.main(ThumbnailView.java:78)
Caused by: java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readShort(Unknown Source)
at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(Unknown Source)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.locateImage(TIFFImageReader.java:204)
can u please suggest me the proper way how to do it..here is m code...

File f = new File("./EJB100.tif");
ImageInputStream streamIn = null;

Iterator readers = ImageIO.getImageReadersByFormatName("tiff");
ImageReadParam readParam = new ImageReadParam();

Iterator it = ImageIO.getImageReadersByFormatName("tiff");

ImageReader tiffReader = null;
while(it.hasNext()){
tiffReader = (ImageReader) it.next();
}
tiffReader.setInput(streamIn);
ImageReadParam temp = tiffReader.getDefaultReadParam();

try {
if(tiffReader.getNumImages(true) > 1) {
BufferedImage thumbnail = tiffReader.read(0,temp);
IIOMetadata thumbnailIFD = tiffReader.getImageMetadata(1);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

robert engels

Please post a COMPLETE test case (that compiles!) that demonstrates
the problem.

On Dec 15, 2006, at 3:03 AM, jai-imageio@javadesktop.org wrote:

> i go through it.my code works fine with jpeg format but when i am
> applying it with the "TIFF" file format it fire the execption.
>
> javax.imageio.IIOException: Couldn't seek!
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.locateImage
> (TIFFImageReader.java:217)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getNumImages
> (TIFFImageReader.java:240)
> at ThumbnailView.(ThumbnailView.java:67)
> at ThumbnailView.main(ThumbnailView.java:78)
> Caused by: java.io.EOFException
> at javax.imageio.stream.ImageInputStreamImpl.readShort(Unknown
> Source)
> at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort
> (Unknown Source)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.locateImage
> (TIFFImageReader.java:204)
> can u please suggest me the proper way how to do it..here is m
> code...
>
> File f = new File("./EJB100.tif");
> ImageInputStream streamIn = null;
>
> Iterator readers = ImageIO.getImageReadersByFormatName("tiff");
> ImageReadParam readParam = new ImageReadParam();
>
> Iterator it = ImageIO.getImageReadersByFormatName("tiff");
>
> ImageReader tiffReader = null;
> while(it.hasNext()){
> tiffReader = (ImageReader) it.next();
> }
> tiffReader.setInput(streamIn);
> ImageReadParam temp = tiffReader.getDefaultReadParam();
>
>
>
> try {
> if(tiffReader.getNumImages(true) > 1) {
> BufferedImage thumbnail = tiffReader.read(0,temp);
> IIOMetadata thumbnailIFD = tiffReader.getImageMetadata(1);
> }
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> [Message sent by forum member 'makwanasonal' (makwanasonal)]
>
> http://forums.java.net/jive/thread.jspa?messageID=186772
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

makwanasonal
Offline
Joined: 2006-10-02

here i am posting my code.

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;

import com.sun.media.imageio.plugins.tiff.TIFFImageReadParam;

public class EmbeddedThumbnail {
public EmbeddedThumbnail(){
File f = new File("./EJB1002.tif");

Iterator readers = ImageIO.getImageReadersByFormatName("tiff");
ImageReader imageReader =null;
ImageReadParam temp = null;
try{
if (readers.hasNext()) {
imageReader= (ImageReader) readers.next();
ImageInputStream imgInputStream = ImageIO.createImageInputStream(new FileInputStream(f));
temp = imageReader.getDefaultReadParam();
imageReader.setInput(imgInputStream);

}
}catch(Exception e){

}

// Read thumbnail and IFD if present.
BufferedImage thumbnail = null;
IIOMetadata thumbnailIFD = null;

try {
if(imageReader.getNumImages(true) >= 1) {
thumbnailIFD = imageReader.getImageMetadata(0);
thumbnail = imageReader.read(0);
System.out.println("Buffereed image"+thumbnail.toString());

}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]){
new EmbeddedThumbnail();
}
}

when i run this code with jpeg file,this code work fine.bt when i applying it with tiff file it gives me folowing error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/medialib/codec/g3fax/Decoder
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:913)
at EmbeddedThumbnail.(EmbeddedThumbnail.java:49)
at EmbeddedThumbnail.main(EmbeddedThumbnail.java:59)

now give me suggestion how to slove it?

robert engels

You need to display the possible first exception...

Change

> }catch(Exception e){
>
> }

To

} catch(Exception e) {
e.printStackTrace();
}

You are probably getting another exception. The other reason may be
that you don't have the proper ImageIO tools.jar installed.

On Dec 15, 2006, at 6:52 AM, jai-imageio@javadesktop.org wrote:

> here i am posting my code.
>
> import java.awt.image.BufferedImage;
> import java.io.ByteArrayInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Iterator;
>
> import javax.imageio.ImageIO;
> import javax.imageio.ImageReadParam;
> import javax.imageio.ImageReader;
> import javax.imageio.metadata.IIOMetadata;
> import javax.imageio.metadata.IIOMetadataNode;
> import javax.imageio.stream.ImageInputStream;
> import javax.imageio.stream.MemoryCacheImageInputStream;
>
> import com.sun.media.imageio.plugins.tiff.TIFFImageReadParam;
>
>
> public class EmbeddedThumbnail {
> public EmbeddedThumbnail(){
> File f = new File("./EJB1002.tif");
>
> Iterator readers = ImageIO.getImageReadersByFormatName("tiff");
> ImageReader imageReader =null;
> ImageReadParam temp = null;
> try{
> if (readers.hasNext()) {
> imageReader= (ImageReader) readers.next();
> ImageInputStream imgInputStream = ImageIO.createImageInputStream
> (new FileInputStream(f));
> temp = imageReader.getDefaultReadParam();
> imageReader.setInput(imgInputStream);
>
> }
> }catch(Exception e){
>
> }
>
>
> // Read thumbnail and IFD if present.
> BufferedImage thumbnail = null;
> IIOMetadata thumbnailIFD = null;
>
> try {
> if(imageReader.getNumImages(true) >= 1) {
> thumbnailIFD = imageReader.getImageMetadata(0);
> thumbnail = imageReader.read(0);
> System.out.println("Buffereed image"+thumbnail.toString());
>
> }
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> public static void main(String args[]){
> new EmbeddedThumbnail();
> }
> }
>
> when i run this code with jpeg file,this code work fine.bt when i
> applying it with tiff file it gives me folowing error:
> Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/
> medialib/codec/g3fax/Decoder
> at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read
> (TIFFImageReader.java:913)
> at EmbeddedThumbnail.(EmbeddedThumbnail.java:49)
> at EmbeddedThumbnail.main(EmbeddedThumbnail.java:59)
>
> now give me suggestion how to slove it?
> [Message sent by forum member 'makwanasonal' (makwanasonal)]
>
> http://forums.java.net/jive/thread.jspa?messageID=186877
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

[att1.html]