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. C#
  4. Overwrite an image after unload it from a picture box control

Overwrite an image after unload it from a picture box control

Scheduled Pinned Locked Moved C#
question
8 Posts 3 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
    t800t8
    wrote on last edited by
    #1

    After I unloaded an image from a picture box like that: if (pictureBox.Image != null){ pictureBox.Image.Dispose(); pictureBox.Image = null; } but when the application is still running, I cannot overwrite this image. How can overwrite it while application is still running? Thanks a lot! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

    C 1 Reply Last reply
    0
    • T t800t8

      After I unloaded an image from a picture box like that: if (pictureBox.Image != null){ pictureBox.Image.Dispose(); pictureBox.Image = null; } but when the application is still running, I cannot overwrite this image. How can overwrite it while application is still running? Thanks a lot! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

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

      I would hope that the picturebox takes care of it's own memory, and you can just assign another image. Christian Graus - Microsoft MVP - C++

      T 1 Reply Last reply
      0
      • C Christian Graus

        I would hope that the picturebox takes care of it's own memory, and you can just assign another image. Christian Graus - Microsoft MVP - C++

        T Offline
        T Offline
        t800t8
        wrote on last edited by
        #3

        Maybe my description has some confusions for you. I don't want to load another image to the pictrue box, I want my program can overwrite the image which I just have unload from the picture box. I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

        C 1 Reply Last reply
        0
        • T t800t8

          Maybe my description has some confusions for you. I don't want to load another image to the pictrue box, I want my program can overwrite the image which I just have unload from the picture box. I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

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

          Are you saying that the picturebox continues to hold a reference to the image, and the image on disc cannot be overwritten as a result ? That seems odd to me, I don't think that Bitmap.FromFile keeps the file open. Christian Graus - Microsoft MVP - C++

          T D 2 Replies Last reply
          0
          • C Christian Graus

            Are you saying that the picturebox continues to hold a reference to the image, and the image on disc cannot be overwritten as a result ? That seems odd to me, I don't think that Bitmap.FromFile keeps the file open. Christian Graus - Microsoft MVP - C++

            T Offline
            T Offline
            t800t8
            wrote on last edited by
            #5

            Extractly! But I don't use Bitmap.FromFile, I used pictureBox.Load(). I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

            C 1 Reply Last reply
            0
            • T t800t8

              Extractly! But I don't use Bitmap.FromFile, I used pictureBox.Load(). I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

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

              The picture box is crap. I dunno why so many people use it. First step, use Bitmap.FromFile, and pass that bitmap in, instead. Then, I don't see you having any issues. Christian Graus - Microsoft MVP - C++

              T 1 Reply Last reply
              0
              • C Christian Graus

                The picture box is crap. I dunno why so many people use it. First step, use Bitmap.FromFile, and pass that bitmap in, instead. Then, I don't see you having any issues. Christian Graus - Microsoft MVP - C++

                T Offline
                T Offline
                t800t8
                wrote on last edited by
                #7

                I will try as your recommendation. Thank you! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

                1 Reply Last reply
                0
                • C Christian Graus

                  Are you saying that the picturebox continues to hold a reference to the image, and the image on disc cannot be overwritten as a result ? That seems odd to me, I don't think that Bitmap.FromFile keeps the file open. Christian Graus - Microsoft MVP - C++

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

                  The Bitmap class inherits from Image and uses Image's FromFile method, which calls a GDI+ Flat API function in GDIPlus.dll (curiously, something you're NOT supposed to do), called GdipLoadImageFromFile to load the image file. It looks like the resulting file handle is never closed so long as the GDI+ Image object exists. As you probably know, the usual workaround was this[^] little article on MSDN. This eventually uses the GdipLoadImageFromStream GDI+ function, which does not hold a handle to the original image stream. In 2005, the PictureBox.Load method calls the static Image.FromStream method, no matter what the actual source of the image is, so locking the image file is not a problem. But, to answer his question, PictureBox.Image = null; should work no problem. I didn't have any at least... ;) RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  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