Download image from URL

How do I download an image to RAM, and not the hard drive then use it’s data to be displayed in for example, an ImageWell. I have tried writing the code for this myself but I get all kinds of errors that force crashes on my application. Things like renavigation of webpages get in the way of downloading certain but not all images from the web. I would at least want to prevent these crashes because it would be really annoying for customers if they accidentally download an image that cannot be downloaded.

Thanks

I have found this site: http://www.freaksw.com/fsindex.html

I found a broken link from this site and it is just telling me to go and find more up to date code.

The simplest way would be something like this using an HTTPSocket and the Picture.FromData shared method.:

  Dim socket As New HTTPSocket
  Dim data As String = socket.Get("http://www.freaksw.com/images/Log2o.jpg", 5) ' using synchronous GET
  
  If socket.HTTPStatusCode = 200 Then ' OK
    ' Picture.FromData creates a new picture from raw binary data
    Dim p As Picture = Picture.FromData(data)
    
    If p <> Nil Then
      ImageWell1.Image = p
    Else
      MsgBox("Not a picture.")
    End If
    
  Else ' errors, redirects, etc.
    MsgBox("HTTP Status: " + Str(socket.HTTPStatusCode))
    
  End If

[quote=45192:@Andrew Lambert]The simplest way would be something like this using an HTTPSocket and the Picture.FromData shared method.:

[code]
Dim socket As New HTTPSocket
Dim data As String = socket.Get(“http://www.freaksw.com/images/Log2o.jpg”, 5) ’ using synchronous GET

If socket.HTTPStatusCode = 200 Then ’ OK
’ Picture.FromData creates a new picture from raw binary data
Dim p As Picture = Picture.FromData(data)

If p <> Nil Then
  ImageWell1.Image = p
Else
  MsgBox("Not a picture.")
End If

Else ’ errors, redirects, etc.
MsgBox("HTTP Status: " + Str(socket.HTTPStatusCode))

End If
[/code][/quote]
Thankyou so much. Excellent!

[quote=45192:@Andrew Lambert]The simplest way would be something like this using an HTTPSocket and the Picture.FromData shared method.:

[code]
Dim socket As New HTTPSocket
Dim data As String = socket.Get(“http://www.freaksw.com/images/Log2o.jpg”, 5) ’ using synchronous GET

If socket.HTTPStatusCode = 200 Then ’ OK
’ Picture.FromData creates a new picture from raw binary data
Dim p As Picture = Picture.FromData(data)

If p <> Nil Then
  ImageWell1.Image = p
Else
  MsgBox("Not a picture.")
End If

Else ’ errors, redirects, etc.
MsgBox("HTTP Status: " + Str(socket.HTTPStatusCode))

End If
[/code][/quote]
but in web application why it occurred unsupportedFormatException ?? picture type .bmp

BMP is not supported in Console apps http://documentation.xojo.com/index.php/Picture.IsImportFormatSupported

Since Web is a console app underneath, it is probably why.