B
Brent Burkart
I have a shopping cart where I have a product page which has an image
webcontrol. In my code behind, I load pictures into the image webcontrol.
I would like to dynamically resize the picture (mostly jpg's) before
displaying the webpage. I have read through some examples, but I am having
all kinds of problems saving my resized image. A piece of my code is below.
I recieve the "A generic error occurred in GDI+" error when I do the save.
Can anyone point out my problem.
Thanks so much
objImage = objImage.FromFile(Server.MapPath(strFilename))
If objImage.Width > objImage.Height Then 'portrait
shtWidth = 350
' Work out a proportionate height from width
shtHeight = objImage.Height / (objImage.Width / shtWidth)
Else 'landscape
shtHeight = 370
' Work out a proportionate width from height
shtWidth = objImage.Width / (objImage.Height / shtHeight)
End If
' Create thumbnail
objThumbnail = objImage.GetThumbnailImage(shtWidth, _
shtHeight, Nothing, System.IntPtr.Zero)
' Send down to client
Response.ContentType = "image/jpeg"
objThumbnail.Save(Path.Combine(Server.MapPath(strPath), strFilename2 & "2"),
Imaging.ImageFormat.Jpeg)
ProductImage.ImageUrl = strFilename2
objImage.Dispose()
objThumbnail.Dispose()
webcontrol. In my code behind, I load pictures into the image webcontrol.
I would like to dynamically resize the picture (mostly jpg's) before
displaying the webpage. I have read through some examples, but I am having
all kinds of problems saving my resized image. A piece of my code is below.
I recieve the "A generic error occurred in GDI+" error when I do the save.
Can anyone point out my problem.
Thanks so much
objImage = objImage.FromFile(Server.MapPath(strFilename))
If objImage.Width > objImage.Height Then 'portrait
shtWidth = 350
' Work out a proportionate height from width
shtHeight = objImage.Height / (objImage.Width / shtWidth)
Else 'landscape
shtHeight = 370
' Work out a proportionate width from height
shtWidth = objImage.Width / (objImage.Height / shtHeight)
End If
' Create thumbnail
objThumbnail = objImage.GetThumbnailImage(shtWidth, _
shtHeight, Nothing, System.IntPtr.Zero)
' Send down to client
Response.ContentType = "image/jpeg"
objThumbnail.Save(Path.Combine(Server.MapPath(strPath), strFilename2 & "2"),
Imaging.ImageFormat.Jpeg)
ProductImage.ImageUrl = strFilename2
objImage.Dispose()
objThumbnail.Dispose()