Sure.
VB Code:
Imports System Imports System.IO Imports System.Net Imports System.Text 'This import is required to gain access to the new namespace Imports LoadImageFromWeb.ImageStream Public Class Form1 Inherits System.Windows.Forms.Form Private Sub btnLoadWebImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadWebImage.Click 'Loads a picture box with an image from a website Const PATH_TO_IMAGE = "http://www.vbforums.com/images/ads/current.gif" Dim xImage As ImageToDownload = New ImageToDownload(PATH_TO_IMAGE) Dim xStream As MemoryStream = xImage.BeginDownload() picFromWeb.Image = Image.FromStream(xStream) End Sub End Class Namespace ImageStream Public Class ImageToDownload Dim sI2D_URL2Download As String Const PREFIX = "http://" Public Sub New(ByVal sURL As String) Me.sI2D_URL2Download = sURL End Sub Public Function BeginDownload() As MemoryStream Dim msImage As MemoryStream Dim wcClient As WebClient = New WebClient() If Not sI2D_URL2Download.ToLower().StartsWith("http://") Then sI2D_URL2Download = PREFIX + sI2D_URL2Download msImage = New MemoryStream(wcClient.DownloadData(sI2D_URL2Download)) Return msImage End Function End Class End Namespace





Reply With Quote