Jump to content

getting an image from web into picturebox.


Recommended Posts

Guest hmcheung
Posted

Hi, I've searched for quite a while but still can't find any luck in grabbing an image from web into a picturebox of my .NET CF application. :) I've read that we've to get a binary stream and then put it into a byte[], then create a second stream to in turn create a Bitmap, then assign this Bitmap to the picturebox.

Is there any examples on that? I've tried a bit but I only get the 'Not Supported' error... thanks!

Guest NeilC_MVP
Posted

To populate a PictureBox with an image from the World Wide Web, you will first need to retrieve the binary stream of the image from the web, then use it to create a new instance of the Bitmap class, which you then can assign to the picturebox's Image property.

The code below does just that:

string url = "http://smartphone.modaco.com/templates/midMoDaCoDude/images/smiles/icon_sad.gif";

HttpWebRequest req (HttpWebRequest)WebRequest.Create(url);

try {

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

if(resp.StatusCode == HttpStatusCode.OK) {

pictureBox1.Image = new Bitmap(resp.GetResponseStream());

}

}

finally {

resp.Close();

}

--Neil

--

Neil Cowburn

Microsoft Windows Embedded MVP (.NET Compact Framework)

www.contentmaster.com | www.opennetcf.org

Guest Paul [MVP]
Posted

Ad a nice topical example too!

Nice one Neil!

:)

P

  • 3 months later...
Posted

Would such an application (ie, one that hits a URL in the manner described) work on an Orange E200 without being signed...?

Or would it be deemed to be requiring "privileged" access because it was going out to the internet?

Guest NeilC_MVP
Posted

Y'know, I've not tried this yet. Although, in theory it shouldn't require privileged rights or it would put a stop to Microsoft's efforts to demonstrate that smart devices (and Smartphone in particular) are first class XML Web Service clients.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.