article

How to Create Thumbnails from PSD Files inside .NET Applications

Email
Submitted on: 1/20/2016 10:22:28 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 2131
 
     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.

 
				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.


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.