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

  • Thread starter Thread starter Marcolino
  • Start date Start date
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
 
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.
 
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
 
Back
Top