Image from website

Hi all I am trying to grab a jpeg from a streaming server that sends jpeg images on request. I have written an application that gets these images in a desktop app that uses

me.picturebox1.imagelocation = http://<path>

and this works great. I now am trying to make a similar app for my new wm5 pocket pc. And i have no imageslocation property in the cf.

I have the following code

Dim req As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create("http://www.google.co.uk/intl/en_uk/images/logo.gif"), Net.HttpWebRequest)

Dim res As Net.HttpWebResponse = DirectCast(req.GetResponse, Net.HttpWebResponse)

Dim img As Image = Image.FromStream(res.GetResponseStream)

But it wont work as i cannot use image.fromstream on the cf. Anyone any great ideas on a way around this or am i approaching this from the wrong direction

Many Thanks

JAmes



Answer this question

Image from website

  • nikos_22

    Spot On Thanks Very much this did it for me

    Private Sub InitializeStreamBitmap()
    Try
    Dim request As System.Net.WebRequest = _
    System.Net.WebRequest.Create( _
    "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif")
    Dim response As System.Net.WebResponse = request.GetResponse()
    Dim responseStream As System.IO.Stream = response.GetResponseStream()
    Dim bitmap2 As New Bitmap(responseStream)
    PictureBox1.Image = bitmap2

    Catch ex As System.Net.WebException
    MessageBox.Show("There was an error opening the image file. Check the URL")
    End Try
    End Sub

    Thanks Again


  • Pablo Jord

    Just use the Bitmap(stream as Stream) constructor instead.
  • Image from website