Last post Sep 07, 2013 08:22 AM by dlchase89
Sep 06, 2013 12:26 PM|dlchase89|LINK
I have an asp.net page that allows the user to do a FileUpload to select an image from their local drive. I am using an asp.net Image control to display the image. However, sometimes the images are pretty large and would like to both save and display the
image in a roughly 200 x 200 image control. How can I accomplish this and also specify the image height and width without losing quality? Thanks.
Sep 06, 2013 02:23 PM|aliadravi|LINK
See this post to upload a single image and save in different resolutions
Upload multiple image in multiple size with progress bar in asp.net
// Get thumb resolution
Size ThumbNailSize100 = NewImageSize(Img.Height, Img.Width, 100, 100);
using (System.Drawing.Image ImgThnail = new Bitmap(Img, ThumbNailSize100.Width, ThumbNailSize100.Height))
For complete code see the link
Sep 06, 2013 02:27 PM|p.pooja10|LINK
refer below articles. they might help you:
you can also use below code which i have used in my application to display images:
byteArray = (byte)s.FileByteArray;
mstream = new System.IO.MemoryStream(byteArray, 0, byteArray.Length);
System.IO.MemoryStream ImgStream2 = new System.IO.MemoryStream(byteArray);
ImgStream2.Position = 0;
System.Drawing.Image dbImage = System.Drawing.Image.FromStream(ImgStream2);
int height = (int)(pct * dbImage.Size.Height);
int width = (int)(pct * dbImage.Size.Width);
if (width > 2948)
width = 2948;
if (height > 4446)
height = 4446;
System.Drawing.Image ImgCopy = dbImage.Clone() as System.Drawing.Image;
Bitmap thumbnailImage = (Bitmap)ImgCopy.GetThumbnailImage(width, height, null, IntPtr.Zero);
System.IO.MemoryStream thumbStream = new System.IO.MemoryStream();
Byte thumbnailByteArray = new Byte[thumbStream.Length];
thumbStream.Position = 0;
thumbStream.Read(thumbnailByteArray, 0, Convert.ToInt32(thumbStream.Length));
catch (Exception e1)
//throw new Exception(e1.ToString());
lblError.Text = e1.Message;
Sep 06, 2013 03:55 PM|dlchase89|LINK
When I try either solution I get the error below when trying to save the image file. The process works fine when I just save the uploaded file without resize.
A generic error occurred in GDI+.
Sep 07, 2013 03:44 AM|webcodeexpert|LINK
I suggest to read and try the article :How to resize image in Asp.net?
Sep 07, 2013 08:22 AM|dlchase89|LINK
Thanks, it worked perfect! I even placed the routine in a shared subroutine to use elsewhere in my app.