C# Source Code: Creating a thumbnail image from an image file
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
C# Source Code
Creating a thumbnail image from an image file
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, April 19, 2005
Hits:
1841
Category:
Unspecified
Article:
Below is an overloaded method (an example code) which shows how to create a thumbnail from an image. using System; using System.Drawing; #region Image Thumbnail ///
/// Creates a thumb nail (of size 64 by 64). ///
///
The path to the image file. ///
Returns the image thumbnail.
///
/// // Get thumb nail (change file name to suite) /// Image thumbnail = GetImageThumbNail(@"c:\test.bmp"); /// // Save thumb nail (change file name to suite) /// thumbnail.Save("C:\test_thumb.jpg"); ///
public static Image GetImageThumbNail(string imageFileName) { return GetImageThumbNail(imageFileName, new Size(64, 64) ); } ///
/// Creates a thumb nail of the specified size. ///
///
The path to the image file. ///
The desired size of the thumbnail. ///
Returns the image thumbnail.
///
/// // Get thumb nail (change file name to suite) /// Image thumbnail = GetImageThumbNail(@"c:\test.bmp"); /// // Save thumb nail (change file name to suite) /// thumbnail.Save("C:\test_thumb.jpg"); ///
public static Image GetImageThumbNail(string imageFileName, Size size) { // Load the image System.Drawing.Image image = System.Drawing.Image.FromFile(imageFileName); // Create the thumbnail image System.Drawing.Image thumbnailImage = image.GetThumbnailImage( size.Width, size.Height, new System.Drawing.Image.GetThumbnailImageAbort( ThumbnailCallback ), IntPtr.Zero); // Return the thumbnail return thumbnailImage; } ///
/// Creates a thumb nail (of size 64 by 64). ///
///
The image to return the thumb nail of. ///
Returns the image thumbnail.
public static Image GetImageThumbNail(Image image) { return GetImageThumbNail(image, new Size(64, 64) ); } ///
/// Creates a thumb nail of the specified size. ///
///
The image to return the thumb nail of. ///
The desired size of the thumbnail. ///
Returns the image thumbnail.
public static Image GetImageThumbNail(Image image, Size size) { // Create the thumbnail image System.Drawing.Image thumbnailImage = image.GetThumbnailImage( size.Width, size.Height, new System.Drawing.Image.GetThumbnailImageAbort( ThumbnailCallback ), IntPtr.Zero); // Return the thumbnail return thumbnailImage; } ///
/// Required for
GetThumbnailImageAbort
. ///
///
Returns false.
private static bool ThumbnailCallback() { return false; } #endregion Image Thumbnail
Terms and Conditions
Support this site
Download a trial version of the best FTP application on the internet