|
-
Apr 8th, 2003, 10:33 AM
#1
Thread Starter
Fanatic Member
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!
-
Apr 8th, 2003, 12:44 PM
#2
PowerPoster
ConfigurationSettings.AppSettings("ImageDataPath")
You might want to see if your final path and file is right. Try constructing the path + filename in a string variable, then check it when debugging to make sure it is a valid path. I don't know how many times I had no \ in there or I had \\'s in the path. That is a place to start anyway.
-
Apr 8th, 2003, 01:51 PM
#3
Thread Starter
Fanatic Member
alright, got stuff working finally, thanks for all your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|