Jump to content


getting an image from web into picturebox.

- - - - -

  • Please log in to reply
6 replies to this topic

#1
hmcheung

hmcheung

    Newbie

  • Members
  • Pip
  • 3 posts
  • Location:Hong Kong
  • Interests:Swimming, Softball
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!

Andy Cheung
Please Visit My WebCam!!
http://www.hmcheung.com

#2
NeilC_MVP

NeilC_MVP

    Newbie

  • Members
  • Pip
  • 44 posts
  • Location:Llanberis, Gwynedd, UK
  • Interests:C#, .NET Compact Framework, Smartphones, Pocket PCs, rock climbing, mountaineering, mountain biking
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

Neil Cowburn
  Microsoft MVP (.NET Compact Framework)

  www.opennetcf.org | http://blog.opennetcf.org/ncowburn/

#3
hmcheung

hmcheung

    Newbie

  • Members
  • Pip
  • 3 posts
  • Location:Hong Kong
  • Interests:Swimming, Softball
Yes this is it! thanks Neil ~  :)  ;)  :D

Andy Cheung
Please Visit My WebCam!!
http://www.hmcheung.com

#4
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 32,961 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:Galaxy Nexus / TF Prime
  • Twitter:@paulobrien
Ad a nice topical example too!

Nice one Neil!

:)

P

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco / Follow MoDaCo Android on Twitter - http://twitter.com/modacoandroid

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#5
NeilC_MVP

NeilC_MVP

    Newbie

  • Members
  • Pip
  • 44 posts
  • Location:Llanberis, Gwynedd, UK
  • Interests:C#, .NET Compact Framework, Smartphones, Pocket PCs, rock climbing, mountaineering, mountain biking
All in a days work :)

Neil Cowburn
  Microsoft MVP (.NET Compact Framework)

  www.opennetcf.org | http://blog.opennetcf.org/ncowburn/

#6
graham

graham

    Newbie

  • Members
  • Pip
  • 22 posts
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?


#7
NeilC_MVP

NeilC_MVP

    Newbie

  • Members
  • Pip
  • 44 posts
  • Location:Llanberis, Gwynedd, UK
  • Interests:C#, .NET Compact Framework, Smartphones, Pocket PCs, rock climbing, mountaineering, mountain biking
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.

Neil Cowburn
  Microsoft MVP (.NET Compact Framework)

  www.opennetcf.org | http://blog.opennetcf.org/ncowburn/




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users