I am using this code I got when I googled. It locks up the form for 4-10 full seconds!Very strange. I have a VERY FAST comp/connection. I am looking for better code that runs smoothly. I'd also like if it fails to load something like error.jpg or something, not just staying blank. I don't know where to throw this in the code. I have only loaded 1 PictureBox on the interface, but in the end, I want to load 6-10 on one form at one time.
Code:Imports System.IO Imports System.Net Imports System.Text Public Sub LoadPics() LoadWebImageToPictureBox(picCrop1, "http://www.sample.com/image.jpg") End Sub Public Function LoadWebImageToPictureBox(ByVal pb _ As PictureBox, ByVal ImageURL As String) As Boolean Dim objImage As MemoryStream Dim objwebClient As WebClient Dim sURL As String = Trim(ImageURL) Dim bAns As Boolean Try If Not sURL.ToLower().StartsWith("http://") _ Then sURL = "http://" & sURL objwebClient = New WebClient() objImage = New _ MemoryStream(objwebClient.DownloadData(sURL)) pb.Image = Image.FromStream(objImage) bAns = True Catch ex As Exception bAns = False End Try Return bAns End Function




Very strange. I have a VERY FAST comp/connection. I am looking for better code that runs smoothly. I'd also like if it fails to load something like error.jpg or something, not just staying blank. I don't know where to throw this in the code. I have only loaded 1 PictureBox on the interface, but in the end, I want to load 6-10 on one form at one time.
Reply With Quote
