how do I load a JPEG into a pictureBox?

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?
 
W

William Ryan

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
 
P

Paul Hetherington

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
 
T

Tim Wilson

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
 

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