Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Story: 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.

like image 684
Brad Tutterow Avatar asked Aug 26 '08 12:08

Brad Tutterow


People also ask

What is a thumbnail in web design?

A thumbnail is a small image representation of a larger image, usually intended to make it easier and faster to look at or manage a group of larger images.


2 Answers

GetThumbnailImage would work, but if you want a little better quality you can specify your image options for the BitMap class and save your loaded image into there. Here is some sample code:

Image photo; // your uploaded image  Bitmap bmp = new Bitmap(resizeToWidth, resizeToHeight); graphic = Graphics.FromImage(bmp); graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; graphic.SmoothingMode = SmoothingMode.HighQuality; graphic.PixelOffsetMode = PixelOffsetMode.HighQuality; graphic.CompositingQuality = CompositingQuality.HighQuality; graphic.DrawImage(photo, 0, 0, resizeToWidth, resizeToHeight); imageToSave = bmp; 

This provides better quality than GetImageThumbnail would out of the box

like image 76
Sean Chambers Avatar answered Oct 06 '22 23:10

Sean Chambers


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);    } } 
like image 33
Huppie Avatar answered Oct 06 '22 22:10

Huppie