views:

299

answers:

3

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
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
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
+1  A: 

There is a nice article here that explains how to do this.

Barry
+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