Home > Code > C# > How to Create Thumbnails from PSD Files inside .NET Applications

How to Create Thumbnails from PSD Files inside .NET Applications

by sher azam   on Jan 20, 2016   Category: C#   |  Views: 550    |  Points: 25   |  Gold 


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. The following code snippet demonstrates the usage of Aspose.Imaging for .NET API to achieve the same.

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



Overview: Aspose.Imaging for .NET

Aspose.Imaging for .NET is an image processing & manipulation component that allows developers to create, edit, draw or convert images in their .NET application. It allows developers to convert image files to PSD, BMP, JPEG, PNG, TIFF and GIF formats. Moreover a set of pens, brushes and fonts can be used to draw images or add new elements & text to existing images. Aspose.Imaging for .NET works well with both web & windows applications. Moreover, it adds the support for Silverlight platform.

- Homepage of Aspose.Imaging for .NET: http://www.aspose.com/.net/imaging-component.aspx

- Download Aspose.Imaging for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.imaging-for-.net/default.aspx



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts