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. Close file open as an image in Picturebox

Close file open as an image in Picturebox

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 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.
  • A Offline
    A Offline
    Amanjot
    wrote on last edited by
    #1

    Hi, I have inserted an image from an existing file which I want to close. I have tried using dispose() command (shown below); however it gives an error. Could some one suggest what would be the command to close the file after the image has been displaced? Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click 'Temperature button pressed Dim iImage As Image iImage = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") 'PictureBox1.Image = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") PictureBox1.Image = iImage iImage.Dispose() End Sub Thanks Aman

    D 1 Reply Last reply
    0
    • A Amanjot

      Hi, I have inserted an image from an existing file which I want to close. I have tried using dispose() command (shown below); however it gives an error. Could some one suggest what would be the command to close the file after the image has been displaced? Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click 'Temperature button pressed Dim iImage As Image iImage = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") 'PictureBox1.Image = Image.FromFile("C:\Aman\ZedGraph\temp.jpeg") PictureBox1.Image = iImage iImage.Dispose() End Sub Thanks Aman

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

      The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object. Instead, you want to do this:

      Dim pic As Bitmap
      Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
      pic = New Bitmap(fs)
      End Using
      PictureBox1.Image = pic

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

      J A 2 Replies Last reply
      0
      • D Dave Kreskowiak

        The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object. Instead, you want to do this:

        Dim pic As Bitmap
        Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
        pic = New Bitmap(fs)
        End Using
        PictureBox1.Image = pic

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

        J Offline
        J Offline
        Jon_Boy
        wrote on last edited by
        #3

        Wasn't this just asked? LOL.

        Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        D 1 Reply Last reply
        0
        • D Dave Kreskowiak

          The problem is you're using Image.FromFile to load the image. This will lock the file for the lifetime of the Image object. Instead, you want to do this:

          Dim pic As Bitmap
          Using fs As New FileStream("C:\Aman\ZeqGraph\temp.jpeg", FileMode.Open, FileAccess.Read)
          pic = New Bitmap(fs)
          End Using
          PictureBox1.Image = pic

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

          A Offline
          A Offline
          Amanjot
          wrote on last edited by
          #4

          Thanks very much Dave, it works now.

          1 Reply Last reply
          0
          • J Jon_Boy

            Wasn't this just asked? LOL.

            Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

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

            Yep, Jan 2 by TheComputerMan. Amazing, noone ever actually reads the forums...

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

            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