I am attempting to convert a multipage Tiff file to Jpeg thumbnails for each page. The following code gives me the correct number of thumbnails, but each is a thumbnail for the first page only.
using (TiffImage tiffImage = (TiffImage)Aspose.Imaging.Image.Load(fullFileName))
{
foreach (TiffFrame tiffFrame in tiffImage…Frames)
{
tiffImage.ActiveFrame = tiffFrame;
size = GetImageSize(tiffImage.Width, tiffImage.Height, thumbnailData);
tmpTNFilename = AsposeUtilities.GetThumbnailFullFileName(thumbnailData.WorkPath, filename, thumbnailData.MediaId, (fPage + 1), “”, extension);
tiffImage.Resize(size.Width, size.Height, ResizeType.NearestNeighbourResample);
tiffImage.Save(tmpTNFilename);
fPage++;
}
}
Hi Mike,
Thank you for contacting Aspose support.
Unfortunately, we are unable to evaluate the presented scenario while using your provided code snippet because it’s incomplete, lacking method definitions for GetThumbnailFullFileName & GetImageSize. Although you may use the below provided code snippet to achieve the same. Please amend the code snippet according to your desired results.
C#
//Create an instance of TiffImage and load an existing image
using (TiffImage multiImage = (TiffImage)Aspose.Imaging.Image.Load(myDir + “merged.tif”))
{
//Create an instance of int to keep track of frames in TiffImage
int frameCounter = 0;
//Iterate over the TiffFrames in TiffImage
foreach (TiffFrame tiffFrame in multiImage.Frames)
{
multiImage.ActiveFrame = tiffFrame;
//Load Pixels of TiffFrame into an array of Colors
Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds);
//Create an instance of JpegOptions
var jpgOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
//Set the Source of JpegOptions as FileCreateSource by specifying the location where output will be saved
//Last boolean parameter denotes isTemporal
jpgOptions.Source = new FileCreateSource(string.Format("{0}\Thumb{1}.jpg", myDir, frameCounter), false);
//Create a new RasterImage of Jpeg type
using (var jpgImage = (RasterImage)Image.Create(jpgOptions, tiffFrame.Width, tiffFrame.Height))
{
//Save the JpegImage with pixels from TiffFrame
jpgImage.SavePixels(tiffFrame.Bounds, pixels);
//Resize the Jpeg Image
jpgImage.Resize(100, 100, ResizeType.NearestNeighbourResample);
//Save the results on disk
jpgImage.Save();
}
frameCounter++;
}
}
Note: The above code requires setting a valid license before instantiating any object from Aspose.Imaging API, otherwise you will experience NullReferenceException on below statement.
C#
jpgImage.SavePixels(tiffFrame.Bounds, pixels);
Please feel free to write back in case you need our further assistance.