How to Create Thumbnails from PSD Files inside .NET Applications

This technical tip explains how .NET developers can create thumbnails from PSD files inside their .NET applications. PSD is the native document format of Adobe's Photoshop application. Adobe Photoshop (version 5.0 and later) stores thumbnail information for preview display in an image resource block that consists of an initial 28-byte header, followed by a JFIF thumbnail in RGB (red, green, blue) order. Aspose.Imaging for .NET API provides an easy to use mechanism to access the resources of PSD file. These resources also include the thumbnail resource that in turn can be fetched and saved to disc as per application needs.
//your code here...// Creating Thumbnails from PSD Files //[C# Code Sample] //Load a PSD in an instance of PsdImage using (Aspose.Imaging.FileFormats.Psd.PsdImage image = (Aspose.Imaging.FileFormats.Psd.PsdImage)Aspose.Imaging.Image.Load(sourceFilePath)) { //Iterate over the PSD resources foreach (var resource in image.ImageResources) { //Check if the resource is of thumbnail type if (resource is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource) { //Retrieve the ThumbnailResource var thumbnail = (Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)resource; //Check the format of the ThumbnailResource if (thumbnail.Format == Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB) { //Create a new BmpImage by specifying the width and heigh Aspose.Imaging.FileFormats.Bmp.BmpImage thumnailImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height); //Store the pixels of thumbnail on to the newly created BmpImage thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData); //Save thumbnail on disc thumnailImage.Save("D:\\test.bmp"); } } } } //[VB.NET Code Sample] 'Load a PSD in an instance of PsdImage Using image As Aspose.Imaging.FileFormats.Psd.PsdImage = CType(Aspose.Imaging.Image.Load(sourceFilePath), Aspose.Imaging.FileFormats.Psd.PsdImage) 'Iterate over the PSD resources For Each resource In image.ImageResources 'Check if the resource is of thumbnail type If TypeOf resource Is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource Then 'Retrieve the ThumbnailResource Dim thumbnail = CType(resource, Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource) 'Check the format of the ThumbnailResource If thumbnail.Format = Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB Then 'Create a new BmpImage by specifying the width and heigh Dim thumnailImage As New Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height) 'Store the pixels of thumbnail on to the newly created BmpImage thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData) 'Save thumbnail on disc thumnailImage.Save("D:\test.bmp") End If End If Next resource End Using

Url: http://www.aspose.com/.net/imaging-component.aspx

Language: C# | User: Sheraz Khan | Created: Jan 20, 2016 | Tags: how to Create Thumbnails from PSD creating Thumbnails from PSD Files access resources of PSD file thumbnail resource of image .NET image processing Check format of the Thumbnail Resource Save image to PNG