CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Upload image to file system and create thumbnail image on the fly in C# and ASP.Net
Submitted By Satheesh Babu B
On 11/18/2008 6:40:19 AM
Tags: ASP.Net,C#,CodeDigest  

 Upload image to file system and Create Thumbnail Image on the Fly in C# and ASP.Net

 

Some times, we require to upload images to file system folder and additionally the thumbnail version of the same image in ASP.Net.

 

 To do this,

Drag a FileUpload(fuImage) control and a button control to upload the image in the ASPX page.

 

 

protected void btnUpload_Click(object sender, EventArgs e)

    {

        string ImgName = fuImage.FileName;

        fuImage.SaveAs(Server.MapPath("~").ToString() +"\\"+ ImgName);       

        Stream imgStream = fuImage.PostedFile.InputStream;

       Bitmap bmThumb = new Bitmap(imgStream);

       System.Drawing.Image im = bmThumb.GetThumbnailImage(100, 100, null, IntPtr.Zero);

       im.Save(Server.MapPath("~").ToString() + "\\ThumbNail_" + ImgName);      

 

    }

 

The above code uses BitMap object to convert the image uploaded to thumbnail image. The GetThubnailImage() method packed with this object takes the dimensions of the thumbnail image as paramter and returns the thumbnail image.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..