Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. GDI+ Error

GDI+ Error

Scheduled Pinned Locked Moved Visual Basic
graphicshelpwinformscomtools
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The ANZAC
    wrote on last edited by
    #1

    Hi all. I am trying to save an image which i am creating in code. Everytime i call the Bitmap.Save Function i get an error "A generic problem occurred in GDI+". I have googled this for the past hour and have been unsuccessful. Her is the source code you need to understand what i am doing. Dim bmp As New Bitmap(80, 80) Dim g As Graphics = Graphics.FromImage(bmp) Dim LinesPen As New Pen(Color.Black, 2) LinesPen.Alignment = Drawing2D.PenAlignment.Center g.DrawRectangle(LinesPen, 1, 1, 78, 78) g.DrawLine(LinesPen, 27, 1, 27, 79) g.DrawLine(LinesPen, 53, 1, 53, 79) g.DrawLine(LinesPen, 1, 27, 79, 27) g.DrawLine(LinesPen, 1, 53, 79, 53) Try '----------------ERROR HERE------------------ bmp.Save(Me.DestinationLabel.Text, System.Drawing.Imaging.ImageFormat.Png) '-------^^^^-----ERROR HERE-------^^^^------- Catch ex As Exception MessageBox.Show(ex.Message) End TryPlease help if you can or if you have also experienced this.

    Please check out my articles: The ANZAC's articles

    L D 2 Replies Last reply
    0
    • T The ANZAC

      Hi all. I am trying to save an image which i am creating in code. Everytime i call the Bitmap.Save Function i get an error "A generic problem occurred in GDI+". I have googled this for the past hour and have been unsuccessful. Her is the source code you need to understand what i am doing. Dim bmp As New Bitmap(80, 80) Dim g As Graphics = Graphics.FromImage(bmp) Dim LinesPen As New Pen(Color.Black, 2) LinesPen.Alignment = Drawing2D.PenAlignment.Center g.DrawRectangle(LinesPen, 1, 1, 78, 78) g.DrawLine(LinesPen, 27, 1, 27, 79) g.DrawLine(LinesPen, 53, 1, 53, 79) g.DrawLine(LinesPen, 1, 27, 79, 27) g.DrawLine(LinesPen, 1, 53, 79, 53) Try '----------------ERROR HERE------------------ bmp.Save(Me.DestinationLabel.Text, System.Drawing.Imaging.ImageFormat.Png) '-------^^^^-----ERROR HERE-------^^^^------- Catch ex As Exception MessageBox.Show(ex.Message) End TryPlease help if you can or if you have also experienced this.

      Please check out my articles: The ANZAC's articles

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, Most, if not all, errors inside GDI+ are reported as "generic problem occurred in GDI+". If the affected line is an Image.Save chances are your path is incorrect or inaccessible, your disk is full, or your destination file exists and is locked. if you load an image from a file, most of the time the file remains locked as long as the Image is alive. This would prevent you from saving an image to the same path. It applies to Image.FromFile, and probably also to PictureBox.ImageLocation The one exception I am aware of is when you use Image.FromStream An alternative work-around is to work with a copy of the image: load the image with Image.FromFile, create a new image from it with new Bitmap(Image), dispose of the original image. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Sorry for any delays in replying, I currently don't get e-mail notifications.


      T 1 Reply Last reply
      0
      • T The ANZAC

        Hi all. I am trying to save an image which i am creating in code. Everytime i call the Bitmap.Save Function i get an error "A generic problem occurred in GDI+". I have googled this for the past hour and have been unsuccessful. Her is the source code you need to understand what i am doing. Dim bmp As New Bitmap(80, 80) Dim g As Graphics = Graphics.FromImage(bmp) Dim LinesPen As New Pen(Color.Black, 2) LinesPen.Alignment = Drawing2D.PenAlignment.Center g.DrawRectangle(LinesPen, 1, 1, 78, 78) g.DrawLine(LinesPen, 27, 1, 27, 79) g.DrawLine(LinesPen, 53, 1, 53, 79) g.DrawLine(LinesPen, 1, 27, 79, 27) g.DrawLine(LinesPen, 1, 53, 79, 53) Try '----------------ERROR HERE------------------ bmp.Save(Me.DestinationLabel.Text, System.Drawing.Imaging.ImageFormat.Png) '-------^^^^-----ERROR HERE-------^^^^------- Catch ex As Exception MessageBox.Show(ex.Message) End TryPlease help if you can or if you have also experienced this.

        Please check out my articles: The ANZAC's articles

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        If you load the image using FromFile, the file is locked for the entire liftime of the image object. This means you cannot save it back to the original file because of the lock. Instead, use the FromStream method to load the image. When you close your FileStream object, the lock is released, then you can save the image back to the original file.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        C 1 Reply Last reply
        0
        • D Dave Kreskowiak

          If you load the image using FromFile, the file is locked for the entire liftime of the image object. This means you cannot save it back to the original file because of the lock. Instead, use the FromStream method to load the image. When you close your FileStream object, the lock is released, then you can save the image back to the original file.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          You're obviously right, but I recently found a case where if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          D 1 Reply Last reply
          0
          • C Christian Graus

            You're obviously right, but I recently found a case where if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Christian Graus wrote:

            if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.

            That's whacked. I haven't seen it happen myself, ...yet. Hmmm. Any clues on the image format that it was using? TIFF, BMP, JPEG, all of the above? Dimensions, color depth, pixel format, compression?

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            C 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Christian Graus wrote:

              if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.

              That's whacked. I haven't seen it happen myself, ...yet. Hmmm. Any clues on the image format that it was using? TIFF, BMP, JPEG, all of the above? Dimensions, color depth, pixel format, compression?

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              They were JPEGs, they were a fair size, and they were 24 bit.

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, Most, if not all, errors inside GDI+ are reported as "generic problem occurred in GDI+". If the affected line is an Image.Save chances are your path is incorrect or inaccessible, your disk is full, or your destination file exists and is locked. if you load an image from a file, most of the time the file remains locked as long as the Image is alive. This would prevent you from saving an image to the same path. It applies to Image.FromFile, and probably also to PictureBox.ImageLocation The one exception I am aware of is when you use Image.FromStream An alternative work-around is to work with a copy of the image: load the image with Image.FromFile, create a new image from it with new Bitmap(Image), dispose of the original image. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Sorry for any delays in replying, I currently don't get e-mail notifications.


                T Offline
                T Offline
                The ANZAC
                wrote on last edited by
                #7

                I am not using FromFile. The image does not exist and is not overwriting another image. It is a completely new image which i have drawn the graphics from then added graphics objects (rectangles and lines) to, i still recive the same error. I just can't save it for some reason. I have no idea why. I have tried making a second image of the same size and making it equal the first one then saving the second one and i still have problems.

                Please check out my articles: The ANZAC's articles

                L 1 Reply Last reply
                0
                • T The ANZAC

                  I am not using FromFile. The image does not exist and is not overwriting another image. It is a completely new image which i have drawn the graphics from then added graphics objects (rectangles and lines) to, i still recive the same error. I just can't save it for some reason. I have no idea why. I have tried making a second image of the same size and making it equal the first one then saving the second one and i still have problems.

                  Please check out my articles: The ANZAC's articles

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  OK, some questions then: 1. is your path correct? 2. do all the (sub)directories exist? 3. is the path refering to an existing file? 4. if so, did that file get created very recently? explain! :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  Sorry for any delays in replying, I currently don't always get e-mail notifications.


                  T 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    OK, some questions then: 1. is your path correct? 2. do all the (sub)directories exist? 3. is the path refering to an existing file? 4. if so, did that file get created very recently? explain! :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Sorry for any delays in replying, I currently don't always get e-mail notifications.


                    T Offline
                    T Offline
                    The ANZAC
                    wrote on last edited by
                    #9

                    Problem Solved, there was a slight error in the way i dealt with the filename.

                    Please check out my articles: The ANZAC's articles

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups