Monday, July 7, 2008

Thumbnails-Part2

Need to include following name spaces
using System.Drawing;
using System.Drawing.Drawing2D;

-------------Code-------------

int width=200;
int height=200;

string Path=server.mappath(".") + "\\UploadPhotos\\hello_old.jpg";

System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(Path);

Bitmap SmallBitmap = new Bitmap(width, height, OriginalImage.PixelFormat);
Graphics SmallImg = Graphics.FromImage(SmallBitmap);



SmallImg.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

SmallImg.DrawImage(OriginalImage, 0, 0, SmallBitmap.Width, SmallBitmap.Height);

//Print to the browser
context.Response.ContentType = "image/jpeg";
SmallBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);

string NewFileName = "";


SmallBitmap.Save(server.mappath(".") + ""\\UploadPhotos\\hello.jpg", ImageFormat.Jpeg);
SmallImg.Dispose();
SmallImg.Dispose();

No comments: