locked
convert image into thumbnail image RRS feed

  • Question

  • User1854681759 posted

    I have tried by this code,  to convert a image into thumbnail but a error ocurred as Out of Memory on the [:)] denoted line.

    protected void button1_Click(object sender, EventArgs e)
            {
                string ImageName = "Zee.jpg";
                //FileUpload1.SaveAs(Server.MapPath("Photos\\") + ImageName);
                string ThumbnailPath = ("f:\\Solution\\Test\\TestProject\\Thumbnail\\" + ImageName);

           [:)]     using (System.Drawing.Image Img =
                     System.Drawing.Image.FromFile("f:\\Solution\\Test\\TestProject\\" + ImageName))
                {
                    Size ThumbNailSize = NewImageSize(Img.Height, Img.Width, 150);

                    using (System.Drawing.Image ImgThnail =
                        new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
                    {
                        ImgThnail.Save(ThumbnailPath, Img.RawFormat);
                        ImgThnail.Dispose();
                    }
                    Img.Dispose();
                }
            }
            public Size NewImageSize(int OriginalHeight, int OriginalWidth, double FormatSize)
            {
                Size NewSize;
                double tempval;

                if (OriginalHeight > FormatSize && OriginalWidth > FormatSize)
                {
                    if (OriginalHeight > OriginalWidth)
                        tempval = FormatSize / Convert.ToDouble(OriginalHeight);
                    else
                        tempval = FormatSize / Convert.ToDouble(OriginalWidth);

                    NewSize = new Size(Convert.ToInt32(tempval * OriginalWidth), Convert.ToInt32(tempval * OriginalHeight));
                }
                else
                    NewSize = new Size(OriginalWidth, OriginalHeight); return NewSize;
            }

    Monday, October 13, 2008 4:48 AM

All replies