vb.net Load JPG in a Picture Box without Locking File

M

Marcolino

Hy Guys,
I have a problem loading JPG in a Picture Box.

I need to load a jpg files into a PB and then unlock the original JPG.
I'm using following code:

Dim picture1 As PictureBox
Dim OriginalImage As New Bitmap(FilePath) 'Load orginal
JPG
Dim iImage As New Bitmap(OriginalImage) 'Copy ii into a
tmp
OriginalImage.Dispose()


picture1.Image = iImage
iImage = Nothing
OriginalImage = Nothing


This code will work sometime yes and some time not.
I mean that sometime the file will unlock immediately, sometime it
takes to unlock 10/20 seconds and sometime never unlock.

Any help would be appreciated.

Many Thanks

Marco
 
M

Michael Phillips, Jr.

I need to load a jpg files into a PB and then unlock the original JPG.

Load it into a memory stream(i.e., Use the FileStream object).
Decode the image using the Bitmap constructor for a stream object.
Once loaded and decoded from the stream, there is no need for the system to
retain a file lock on the original file.
 
T

tommaso.gastaldi

Hy Guys,
I have a problem loading JPG in a Picture Box.

I need to load a jpg files into a PB and then unlock the original JPG.
I'm using following code:

Dim picture1 As PictureBox
Dim OriginalImage As New Bitmap(FilePath) 'Load orginal
JPG
Dim iImage As New Bitmap(OriginalImage) 'Copy ii into a
tmp
OriginalImage.Dispose()

picture1.Image = iImage
iImage = Nothing
OriginalImage = Nothing

This code will work sometime yes and some time not.
I mean that sometime the file will unlock immediately, sometime it
takes to unlock 10/20 seconds and sometime never unlock.

Any help would be appreciated.

Many Thanks

Marco

Probably the easiest thing is just to draw the image on a new bitmap
created in memory
and, then, use this bitmap as image for the picture box.



Tommaso
http://groups.google.it/group/DataTime
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top