VB Code:
'WEB CLIENT IS NEEDED TO DO THE DOWNLOAD Dim MyWebClient As New System.Net.WebClient 'BYTE ARRAY HOLDS THE DATA Dim ImageInBytes() As Byte = MyWebClient.DownloadData(TextBox1.Text) 'CREATE A MEMORY STREAM USING THE BYTES Dim ImageStream As New IO.MemoryStream(ImageInBytes) 'CREATE A BITMAP FROM THE MEMORY STREAM PictureBox1.Image = New System.Drawing.Bitmap(ImageStream) 'AS U SEE, NO FILE NEEDS TO BE WRITTEN TO THE HARD DRIVE, ITS ALL DONE IN MEMORY
Or to merge all that into 1 line of code
VB Code:
PictureBox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(TextBox1.Text)))
Assumes there is a textbox called textbox1 and a picturebox called picturebox1 on a form. Textbox1.text should be the URL of the picture.
This shows how you can grab a picture off the web in .NET 1.1 and display it in a picturebox without actually having to save the image to file first. It uses a memory stream so no data has to be physically written to the drive to then be displayed.
The example uses an image, and a picturebox, but you can see how this could be applied to other file types and used with other classes that can be created via a stream or bytes.




Reply With Quote