Closed ivanooi closed 6 years ago
ICAFE has a special data type called Thumbnail to handle different kinds of thumbnails. Internally, it is either in Tiff/Jpeg or BufferedImage which we call it raw format. I am not sure what exactly you mean by saying return thumbnail as byte array. The current implementation detail is: if it is in Tiff or Jpeg format, you can grab it as a byte array in that format otherwise you can grab it as BufferedImage. Please let me know more details about your use case and requirements.
Wen
This is the sample code. directly convert byte array into image and display it into SWT table row.
inputStreamReader = new BufferedInputStream( new ByteArrayInputStream( lbyt_array ));
image = new org.eclipse.swt.graphics.Image( Display, new ImageData( inputStreamReader ));
itblitm_row.setImage( 1, image ); //Photo
Thanks
Try this - first assume you have already got a Thumbnail instance called thumbnail: // To get a Thumbnail, you can either create one or extract it from a Metada.readMetadata. I assume you // got it from the later.
int dataType thumbnail.getDataType();
if(dataType == Thumbnail.DATA_TYPE_KJpegRGB || dataType == Thumbnail.DATA_TYPE_TIFF) {
lbyt_array = thumbnail.getCompressedImage();
inputStreamReader = new BufferedInputStream( new ByteArrayInputStream( lbyt_array ));
image = new org.eclipse.swt.graphics.Image( Display, new ImageData( inputStreamReader ));
itblitm_row.setImage( 1, image ); //Photo
}
This will work almost all of the time (unless the thumbnail is in some raw data type). The compressed data byte array will be either in Jpeg or Tiff format.
Let me know if it works or if you have question about how to extract Thumbnail from reading metadata.
Wen
Hi,
I found this Metadata.extractThumbnails
but it return nothing.
I can't find this statement Thumbnail.getCompressedImage();
Thanks again
I believe should be like this :
metadataMap.get(MetadataType.IMAGE );
Exif exif = (JpegExif)metadataMap.get(MetadataType.EXIF );
ExifThumbnail thumbnail = exif .getThumbnail();
thumbnail.getCompressedImage();
It work! Thanks again! :-D
You are right but that's one specific way of get Exif thumbnail. A generic way to get Thumbnail which is the super class of all kinds of thumbnails is like this:
Map<MetadataType, Metadata> metadataMap = Metadata.readMetadata(InputStream is);
if(metadataMap.get(MetadataType.IMAGE) != null) {
ImageMetadata im = (ImageMetadata)metadataMap.get(MetadataType.IMAGE);
if(im.containsThumbnail()) {
Map<String, Thumbnail> thumbnailMap = im.getThumbnails(); // Usually one image only has one thumbnail
// Get the first entry that the iterator returns
Map.Entry<String, Thumbnail> entry = thumbnailMap.entrySet().iterator().next(); // Need to do null check
Thumbnail thumbnail = entry.getValue();
}
}
Metadata.readMetadata() used to extract thumbnails from JPEG only, I checked in some code early today so it will extract thumbnail from TIFF too.
After you grab the Thumbnail, you can use the code I provided in the previous response to show it by Eclipse SWT.
ya, you are right! the above code better! Thanks again
Hi,
Is there anyway to return Thumbnails as byte array?
Thanks