Results 1 to 3 of 3

Thread: GDI+ Generic Error While Saving Image

  1. #1

    Thread Starter
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551

    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:
    1. ' Declarations
    2.                     Dim intWidth As Integer
    3.                     Dim intHeight As Integer
    4.                     Dim sizeMain As SizeF
    5.                     Dim sizeNew As SizeF
    6.                     Dim sizeNewThumb As SizeF
    7.                     Dim fScale As Single
    8.  
    9.                     ' New Bitmaps for modified images
    10.                     Dim bmpNew As Bitmap
    11.                     Dim bmpNewThumb As Bitmap
    12.  
    13.                     ' Get Uploaded picture
    14.                     Dim bmpMain As New Bitmap(filePicture.PostedFile.InputStream)
    15.  
    16.                     'Get the original size of the picture
    17.                     sizeMain = New SizeF(bmpMain.Width / bmpMain.HorizontalResolution, bmpMain.Height / bmpMain.VerticalResolution)
    18.  
    19.  
    20.                     ' Create the Main Picture and save it
    21.                     ' Set the maximum picture width
    22.                     intWidth = 200
    23.                     intHeight = 200
    24.  
    25.                     'Always resize this image, to keep things constant
    26.                     If CInt(sizeMain.Width) > intWidth Or CInt(sizeMain.Height) > intHeight Then
    27.  
    28.                         'Get scale at how to change image
    29.                         fScale = Math.Min(intWidth / sizeMain.Width, intHeight / sizeMain.Height)
    30.  
    31.                         'Get new image size
    32.                         sizeNew = New SizeF(sizeMain.Width, sizeMain.Height)
    33.  
    34.  
    35.                         ' Calculate the new height and width
    36.                         sizeNew.Width *= fScale
    37.                         sizeNew.Height *= fScale
    38.  
    39.                         'Get Thumbnail
    40.                         bmpNew = bmpMain.GetThumbnailImage(CInt(sizeNewThumb.Width), CInt(sizeNewThumb.Height), Nothing, Nothing)
    41.                     Else
    42.                         bmpNew = bmpMain
    43.                     End If
    44.  
    45.                     'Finally save the image
    46.                     bmpNew.Save(ConfigurationSettings.AppSettings("ImageDataPath") & lblProductID.Text & "_TEMP.jpg", Drawing.Imaging.ImageFormat.Jpeg)
    47.  
    48.                     'Create the Thumbnail Image
    49.                     'Set Thumbnail dimensions
    50.                     intWidth = 75
    51.                     intHeight = 75
    52.  
    53.                     'Always resize this image, to keep things constant
    54.  
    55.                     'Get scale at how to change image
    56.                     fScale = Math.Min(intWidth / sizeMain.Width, intHeight / sizeMain.Height)
    57.  
    58.                     'Get new image size
    59.                     sizeNewThumb = New SizeF(sizeMain.Width, sizeMain.Height)
    60.  
    61.  
    62.                     ' Calculate the new height and width
    63.                     sizeNewThumb.Width *= fScale
    64.                     sizeNewThumb.Height *= fScale
    65.  
    66.                     'Get Thumbnail
    67.                     bmpNewThumb = bmpMain.GetThumbnailImage(CInt(sizeNewThumb.Width), CInt(sizeNewThumb.Height), Nothing, Nothing)
    68.                     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!

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  3. #3

    Thread Starter
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    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
  •  



Click Here to Expand Forum to Full Width