how do I load a JPEG into a pictureBox?

  • Thread starter Thread starter rocio
  • Start date Start date
R

rocio

Yes, this is staright forward but this code does not work:

PictureBox1.Image = new Bitmap("\SD Card\myfile.jpg")
PictureBox1.Update()

however if I load a specific BMP file it gets displayed. So how do I load a
jpEG then?
 
Rocio:

If you use Debug.Assert(File.Exists("\SD Card\myfile.jpg")) does the
assertion fail? That code should work , and even though it's a jpg, that
shouldn't matter. You may want to use an embedded resource..if you add the
file to your project and then set it's build action to embedded resource.
From there...MyPictureBox1.Image = New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceSt
ream("MyProjectName.filename.jpg")

Embedded images aren't the answer to every problem b/c they can cause your
project to get rather large if they are overused, however, if you onlyhave a
few, they relieve you from having to worry about making sure the file is in
the right place and no one has deleted it.

HTH,

Bill
 
Try something like this.
Dim fs as New IO.FileStream("file to open"...)
Dim jpgImage as Image=Image.FromStream(fs)
PicturBox1.IMage=jpgImage
fs.flush
fs.close

Cheers,
Paul
 
This has come up in the past. However, if this is truely the same type of
problem as has been seen before, I don't know if there is a solution as I
don't think that anyone has determined the cause. Here is a recent
discussion on this matter:
http://tinyurl.com/yv2jf

You might also want to google some more and look at some of the other posts
that have been made in the past on this issue.

In addition, there is an entry in the FAQ that you may want to look at. I
don't think that this will be you're problem but it might be worth looking
into just in case.
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/faq/default.aspx#2.9
 
Back
Top