Home All Groups Group Topic Archive Search About
Author
1 Apr 2006 11:26 PM
Paul Hadfield
Hi Guys,

Real simple question here I'm sure. I'm trying to display a JPEG in a
picture box (VB.NET 2003).

     pb.Image = Image.FromFile("C:\pic.jpg")

Then, later in the program I need to delete the image file from the disk.

     pb.Image = Nothing
     IO.File.Delete("C:\pic.jpg")

But I can't as the file is still open/in use. If I try to delete the image
file without displaying it in the picture box first it deletes fine, so I
know it's the picture box that's still got hold of the image file somehow.

What am I missing?


Cheers,
Paul.

Author
2 Apr 2006 2:15 AM
Ken Tucker [MVP]
Hi,

Dim fs As New System.IO.FileStream("C:\bliss.jpg", IO.FileMode.Open)

Dim bm As New Bitmap(fs)

PictureBox1.Image = DirectCast(bm.Clone, Image)

fs.Close()

bm.Dispose()

System.IO.File.Delete("C:\bliss.jpg")



Ken

------------------

Show quoteHide quote
"Paul Hadfield" <paul@nospamthankyoumam.com> wrote in message
news:OTNwLPeVGHA.4864@TK2MSFTNGP12.phx.gbl...
> Hi Guys,
>
> Real simple question here I'm sure. I'm trying to display a JPEG in a
> picture box (VB.NET 2003).
>
>     pb.Image = Image.FromFile("C:\pic.jpg")
>
> Then, later in the program I need to delete the image file from the disk.
>
>     pb.Image = Nothing
>     IO.File.Delete("C:\pic.jpg")
>
> But I can't as the file is still open/in use. If I try to delete the image
> file without displaying it in the picture box first it deletes fine, so I
> know it's the picture box that's still got hold of the image file somehow.
>
> What am I missing?
>
>
> Cheers,
> Paul.
>
>
Author
2 Apr 2006 11:29 AM
Paul Hadfield
Thanks Ken - perfect.

Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ek%23uZtfVGHA.2276@tk2msftngp13.phx.gbl...
> Hi,
>
> Dim fs As New System.IO.FileStream("C:\bliss.jpg", IO.FileMode.Open)
>
> Dim bm As New Bitmap(fs)
>
> PictureBox1.Image = DirectCast(bm.Clone, Image)
>
> fs.Close()
>
> bm.Dispose()
>
> System.IO.File.Delete("C:\bliss.jpg")
>
>
>
> Ken
>
> ------------------
>
> "Paul Hadfield" <paul@nospamthankyoumam.com> wrote in message
> news:OTNwLPeVGHA.4864@TK2MSFTNGP12.phx.gbl...
>> Hi Guys,
>>
>> Real simple question here I'm sure. I'm trying to display a JPEG in a
>> picture box (VB.NET 2003).
>>
>>     pb.Image = Image.FromFile("C:\pic.jpg")
>>
>> Then, later in the program I need to delete the image file from the disk.
>>
>>     pb.Image = Nothing
>>     IO.File.Delete("C:\pic.jpg")
>>
>> But I can't as the file is still open/in use. If I try to delete the
>> image file without displaying it in the picture box first it deletes
>> fine, so I know it's the picture box that's still got hold of the image
>> file somehow.
>>
>> What am I missing?
>>
>>
>> Cheers,
>> Paul.
>>
>>
>
>
Author
2 Apr 2006 10:44 AM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Paul Hadfield" <paul@nospamthankyoumam.com> schrieb:
> Real simple question here I'm sure. I'm trying to display a JPEG in a
> picture box (VB.NET 2003).
>
>     pb.Image = Image.FromFile("C:\pic.jpg")
>
> Then, later in the program I need to delete the image file from the disk.
>
>     pb.Image = Nothing
>     IO.File.Delete("C:\pic.jpg")
>
> But I can't as the file is still open/in use. If I try to delete the image
> file without displaying it in the picture box first it deletes fine, so I
> know it's the picture box that's still got hold of the image file somehow.

Check out the code listings at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
3 Apr 2006 12:10 AM
Cerebrus
Hi Herfried,

Herfried wrote :

>> Check out the code listings at ...

I've been meaning to ask you this for some time now... Do you have an
English version of your site ? There's so much information there that I
would like to learn, but the language barrier ... ! I did do a course
in German language many years back, but my German is too rusty to be
able to understand technicalities. ;-)

Thanks,

Cerebrus.
Author
3 Apr 2006 2:41 AM
Rocky
Just go to google and put in the web address then click search.  A seach
page should come up with a tranlate link. It's not perfect but it does the
job.

http://translate.google.com/translate?hl=en&sl=de&u=http://dotnet.mvps.org/dotnet/code/graphics/&prev=/search%3Fq%3Dhttp://dotnet.mvps.org/dotnet/code/graphics/%26hl%3Den%26lr%3D



Show quoteHide quote
"Cerebrus" <zorg***@sify.com> wrote in message
news:1144023058.288934.263720@t31g2000cwb.googlegroups.com...
> Hi Herfried,
>
> Herfried wrote :
>
>>> Check out the code listings at ...
>
> I've been meaning to ask you this for some time now... Do you have an
> English version of your site ? There's so much information there that I
> would like to learn, but the language barrier ... ! I did do a course
> in German language many years back, but my German is too rusty to be
> able to understand technicalities. ;-)
>
> Thanks,
>
> Cerebrus.
>
Author
3 Apr 2006 10:45 AM
Herfried K. Wagner [MVP]
"Cerebrus" <zorg***@sify.com> schrieb:
>>> Check out the code listings at ...
>
> I've been meaning to ask you this for some time now... Do you have an
> English version of your site ? There's so much information there that I
> would like to learn, but the language barrier ... ! I did do a course
> in German language many years back, but my German is too rusty to be
> able to understand technicalities. ;-)

Sorry, but I currently do not plan an English translation.  However, the
tips in the FAQ collection are available in English!

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>