Thursday, January 22, 2009

Image resize using GetThumbnailImage Function

Image resize using .GetThumbnailImage Function
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO.Compression;
using System.Drawing.Drawing2D;

public partial class ImageResize : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

Image thumbnailImage;
Bitmap originalImage;

originalImage = new Bitmap("E:\\Retreat.jpg");
int imgHeight = originalImage.Height;
int imgWidht = originalImage.Width;
string format = Convert.ToString(originalImage.RawFormat);
ImageFormat imageFormat;

switch (format)
case ("gif"):
imageFormat = ImageFormat.Gif;
imageFormat = ImageFormat.Jpeg;
format = "jpg";

if (imgWidht == 0)
{ imgWidht = 100; }

if (imgHeight == 0)
{ imgHeight = imgWidht; }

string ImageSavePath = "E:\\jj1234.jpg";
thumbnailImage = originalImage.GetThumbnailImage(imgWidht, imgHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailImageAbortDelegate), IntPtr.Zero);
thumbnailImage.Save(ImageSavePath, imageFormat);
protected static bool ThumbnailImageAbortDelegate() { return false; }

1 comment:

Administrator said...

I found a free online image resizer called QuickResizer Image Resizer. If you are away from your PC and don't want to download any software, you can just use this online version for free. It's quick and it's easy to use.

You can also download their full version of QuickResizer image resizer if you want to resize multiple files in a folder with just a click of the mouse.