Results 1 to 5 of 5

Thread: How to get an image in a picture box

  1. #1

    Thread Starter
    Addicted Member Buy2easy.com's Avatar
    Join Date
    Jul 2002
    Posts
    200

    How to get an image in a picture box

    how can i get an image from a url and put it in a picture box

    for instance picturebox1 needs to have the image http://somewhere.com/img.gif how can i get it in there without having to save the image to my hard drive then placing it in the picture box?? thanks!!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Addicted Member Buy2easy.com's Avatar
    Join Date
    Jul 2002
    Posts
    200
    do you got a link to one in vb.net or would you mind converting the code in c# to vb.net

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Cool

    Sure.

    VB Code:
    1. Imports System
    2. Imports System.IO
    3. Imports System.Net
    4. Imports System.Text
    5. 'This import is required to gain access to the new namespace
    6. Imports LoadImageFromWeb.ImageStream
    7.  
    8. Public Class Form1
    9.     Inherits System.Windows.Forms.Form
    10.     Private Sub btnLoadWebImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadWebImage.Click
    11.         'Loads a picture box with an image from a website
    12.         Const PATH_TO_IMAGE = "http://www.vbforums.com/images/ads/current.gif"
    13.         Dim xImage As ImageToDownload = New ImageToDownload(PATH_TO_IMAGE)
    14.         Dim xStream As MemoryStream = xImage.BeginDownload()
    15.         picFromWeb.Image = Image.FromStream(xStream)
    16.     End Sub
    17.  
    18. End Class
    19.  
    20. Namespace ImageStream
    21.  
    22.     Public Class ImageToDownload
    23.         Dim sI2D_URL2Download As String
    24.         Const PREFIX = "http://"
    25.  
    26.         Public Sub New(ByVal sURL As String)
    27.             Me.sI2D_URL2Download = sURL
    28.         End Sub
    29.  
    30.         Public Function BeginDownload() As MemoryStream
    31.             Dim msImage As MemoryStream
    32.             Dim wcClient As WebClient = New WebClient()
    33.  
    34.             If Not sI2D_URL2Download.ToLower().StartsWith("http://") Then sI2D_URL2Download = PREFIX + sI2D_URL2Download
    35.             msImage = New MemoryStream(wcClient.DownloadData(sI2D_URL2Download))
    36.  
    37.             Return msImage
    38.         End Function
    39.     End Class
    40.  
    41. End Namespace
    ~Peter


  5. #5

    Thread Starter
    Addicted Member Buy2easy.com's Avatar
    Join Date
    Jul 2002
    Posts
    200
    Thanks a lot you are a big help!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width