←Select platform

ReadThumbnail(Stream,CodecsThumbnailOptions,int) Method

Summary
Creates a thumbnail from the specified image stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterImage ReadThumbnail( 
   Stream stream, 
   CodecsThumbnailOptions options, 
   int pageNumber 
) 
- (nullable LTRasterImage *)readThumbnailFromStream:(LTLeadStream *)stream  
                                            options:(LTCodecsThumbnailOptions *)thumbnailOptions  
                                         pageNumber:(NSInteger)pageNumber  
                                              error:(NSError **)error 
public RasterImage readThumbnail(ILeadStream stream, CodecsThumbnailOptions options, int pageNumber) 
public: 
RasterImage^ ReadThumbnail(  
   Stream^ stream, 
   CodecsThumbnailOptions options, 
   int pageNumber 
)  
def ReadThumbnail(self,stream,options,pageNumber): 

Parameters

stream
A Stream containing the image data from which the thumbnail image will be created.

options
Options for creating the thumbnail image.

pageNumber
1-based index of the page from which the thumbnail image should be created.

Return Value

The RasterImage object that this method creates.

Remarks

This method will always return a thumbnail image. Depending on the  options passed, this method might read the stamp stored inside EXIF, CMP, JFIF and FlashPix files and return that. To read the file stamp only, use ReadStamp.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void ReadThumbnailExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
 
   // Create a thumbnail with default options 
   CodecsThumbnailOptions options = CodecsThumbnailOptions.Default; 
   options.LoadStamp = false; 
   RasterImage thumbnail = codecs.ReadThumbnail(srcFileName, options, 1); 
 
   Debug.WriteLine("Thumbnail with default option:"); 
   Debug.WriteLine("  Size: {0} by {1} pixels. Bits/Pixel: {2}", thumbnail.Width, thumbnail.Height, thumbnail.BitsPerPixel); 
   thumbnail.Dispose(); 
 
   // Create a thumbnail with some options 
   options.LoadStamp = false; 
   options.Width = 40; 
   options.Height = 80; 
   options.ForceSize = true; 
   options.MaintainAspectRatio = false; 
   options.BackColor = RasterColor.FromKnownColor(RasterKnownColor.LightBlue); 
   options.BitsPerPixel = 8; 
   options.DitheringMethod = RasterDitheringMethod.None; 
   options.Order = RasterByteOrder.Rgb; 
   options.PaletteFlags = ColorResolutionCommandPaletteFlags.None; 
   options.Resample = false; 
   thumbnail = codecs.ReadThumbnail(srcFileName, options, 1); 
 
   Debug.WriteLine("Thumbnail with set option (size: {0} by {1}, Bits/Pixel: {2}, ForeSize: {3}", 
      options.Width, options.Height, options.BitsPerPixel, options.ForceSize); 
   Debug.WriteLine("  Size: {0} by {1} pixels. Bits/Pixel: {2}", thumbnail.Width, thumbnail.Height, thumbnail.BitsPerPixel); 
   thumbnail.Dispose(); 
 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
public void readThumbnailExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp"); 
 
   // Create a thumbnail with default options 
   CodecsThumbnailOptions options = CodecsThumbnailOptions.getDefault(); 
   options.setLoadStamp(false); 
   ILeadStream srcFileStream = LeadStreamFactory.create(srcFileName); 
   RasterImage thumbnail = codecs.readThumbnail(srcFileStream, options, 1); 
 
   System.out.println("Thumbnail with default option:"); 
   System.out.println("  Size: " + thumbnail.getWidth() + " by " + thumbnail.getHeight() + " pixels. Bits/Pixel: " 
         + thumbnail.getBitsPerPixel()); 
   thumbnail.dispose(); 
 
   // Create a thumbnail with some options 
   options.setLoadStamp(false); 
   options.setWidth(40); 
   options.setHeight(80); 
   options.setForceSize(true); 
   options.setMaintainAspectRatio(false); 
   options.setBackColor(RasterColor.fromKnownColor(RasterKnownColor.LIGHT_BLUE)); 
   options.setBitsPerPixel(8); 
   options.setDitheringMethod(RasterDitheringMethod.NONE); 
   options.setOrder(RasterByteOrder.RGB); 
   options.setPaletteFlags(ColorResolutionCommandPaletteFlags.NONE); 
   options.setResample(false); 
   thumbnail = codecs.readThumbnail(srcFileStream, options, 1); 
 
   assertTrue("Incorrect dithering method", options.getDitheringMethod().equals(RasterDitheringMethod.NONE)); 
   System.out.println("Correct dithering method was used"); 
 
   System.out.printf("Thumbnail with set option (size: %s by %s, Bits/Pixel: %s, ForeSize: %s%n", 
         options.getWidth(), options.getHeight(), options.getBitsPerPixel(), options.getForceSize()); 
   System.out.printf("  Size: %s by %s pixels. Bits/Pixel: %s%n", thumbnail.getWidth(), thumbnail.getHeight(), 
         thumbnail.getBitsPerPixel()); 
   thumbnail.dispose(); 
 
   srcFileStream.close(); 
   codecs.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.