Hi,I want to display the thumbnail image in grid view from file location . how to generate that of .jpeg file I am using C# language with asp.net
+6
A:
You want to use GetThumbnailImage in the Image class:
http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx
Here's a rough example that takes an image file and makes a thumbnail image from it, then saves it back to disk.
Image image = Image.FromFile(fileName);
Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(textBox1.Text, "thumb"));
Russell Troywest
2010-05-11 07:53:24
Wow, I'm impressed. .Net is really comprehensive as framework. I have been using .Net on and off for five years but did not know about this. You get +1 from me!
hitec
2010-05-11 08:00:54
It's frightening how much the framework can do for you. You'll find useful and powerful tools like this all through it.
Russell Troywest
2010-05-11 08:03:54
+1
A:
The following code will write an image in proportional to the response, you can modify the code for your purpose
public void WriteImage(string path, int width, int height)
{
Bitmap srcBmp = new Bitmap(path);
float ratio = srcBmp.Width / srcBmp.Height;
SizeF newSize = new SizeF(width, height * ratio);
Bitmap target = new Bitmap((int) newSize.Width,(int) newSize.Height);
HttpContext.Response.Clear();
HttpContext.Response.ContentType = "image/jpeg";
using (Graphics graphics = Graphics.FromImage(target))
{
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.DrawImage(srcBmp, 0, 0, newSize.Width, newSize.Height);
using (MemoryStream memoryStream = new MemoryStream()) {
target.Save(memoryStream, ImageFormat.Jpeg);
memoryStream.WriteTo(HttpContext.Response.OutputStream);
}
}
Response.End();
}
Priyan R
2010-05-11 08:03:43