GDI+ Generic Error While Saving Image
hey guys, i'm getting a Generic GDI+ error when saving an image to a filepath... The reason this is so odd, is the first image which i make (bmpNew) is where i get the error... however, the second image (bmpNewThumb) saves perfectly fine... both images are just sizes of the main image (bmpMain)
anyways, here's my code.. i've been picking through it forever and can't seem to find what's wrong...
VB Code:
' Declarations
Dim intWidth As Integer
Dim intHeight As Integer
Dim sizeMain As SizeF
Dim sizeNew As SizeF
Dim sizeNewThumb As SizeF
Dim fScale As Single
' New Bitmaps for modified images
Dim bmpNew As Bitmap
Dim bmpNewThumb As Bitmap
' Get Uploaded picture
Dim bmpMain As New Bitmap(filePicture.PostedFile.InputStream)
'Get the original size of the picture
sizeMain = New SizeF(bmpMain.Width / bmpMain.HorizontalResolution, bmpMain.Height / bmpMain.VerticalResolution)
' Create the Main Picture and save it
' Set the maximum picture width
intWidth = 200
intHeight = 200
'Always resize this image, to keep things constant
If CInt(sizeMain.Width) > intWidth Or CInt(sizeMain.Height) > intHeight Then
'Get scale at how to change image
fScale = Math.Min(intWidth / sizeMain.Width, intHeight / sizeMain.Height)
'Get new image size
sizeNew = New SizeF(sizeMain.Width, sizeMain.Height)
' Calculate the new height and width
sizeNew.Width *= fScale
sizeNew.Height *= fScale
'Get Thumbnail
bmpNew = bmpMain.GetThumbnailImage(CInt(sizeNewThumb.Width), CInt(sizeNewThumb.Height), Nothing, Nothing)
Else
bmpNew = bmpMain
End If
'Finally save the image
bmpNew.Save(ConfigurationSettings.AppSettings("ImageDataPath") & lblProductID.Text & "_TEMP.jpg", Drawing.Imaging.ImageFormat.Jpeg)
'Create the Thumbnail Image
'Set Thumbnail dimensions
intWidth = 75
intHeight = 75
'Always resize this image, to keep things constant
'Get scale at how to change image
fScale = Math.Min(intWidth / sizeMain.Width, intHeight / sizeMain.Height)
'Get new image size
sizeNewThumb = New SizeF(sizeMain.Width, sizeMain.Height)
' Calculate the new height and width
sizeNewThumb.Width *= fScale
sizeNewThumb.Height *= fScale
'Get Thumbnail
bmpNewThumb = bmpMain.GetThumbnailImage(CInt(sizeNewThumb.Width), CInt(sizeNewThumb.Height), Nothing, Nothing)
bmpNewThumb.Save(ConfigurationSettings.AppSettings("ImageDataPath") & lblProductID.Text & "_TEMP_THUMB.jpg", Drawing.Imaging.ImageFormat.Jpeg)
like i said, the bmpNew.Save is the line where i'm getting the error... it just doesn't add up to me... :/ thanks for the help!