Clickadilla

Easy Technical Solutions

What is the "best" way to create a thumbnail using ASP.NET?

 

What is the "best" way to create a thumbnail using ASP.NET?

Scenario: The user uploads an image that will be added to a photo gallery. As part of the upload process, we need to A) store the image on the web server's hard drive and B) store a thumbnail of the image on the web server's hard drive.

"Best" here is defined as

  • Relatively easy to implement, understand, and maintain
  • Results in a thumbnail of reasonable quality

Performance and high-quality thumbnails are secondary.

Solution: 

 I suppose your best solution would be using the GetThumbnailImage from the .NET Image class.

// Example in C#, should be quite alike in ASP.NET
// Assuming filename as the uploaded file
using ( Image bigImage = new Bitmap( filename ) )
{
   // Algorithm simplified for purpose of example.
   int height = bigImage.Height / 10;
   int width = bigImage.Width / 10;

   // Now create a thumbnail
   using ( Image smallImage = image.GetThumbnailImage( width, 
                                                       height,
                                                       new Image.GetThumbnailImageAbort(Abort), IntPtr.Zero) )
   {
      smallImage.Save("thumbnail.jpg", ImageFormat.Jpeg);
   }
}

 ©2024, Easy Tech Solution

 

Post a Comment

0 Comments