Results 1 to 3 of 3

Thread: Display list of images from internet

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    47

    Display list of images from internet

    If I have an array of urls which link to images, how can I list them as thumbnails in my application?

  2. #2
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    452

    Re: Display list of images from internet

    is your question about the array part, picturebox part, or the resize part?

    to assign a picture box a url, use this code:
    Code:
     Me.PictureBox1.ImageLocation = "http://someaddress/somepic.jpg"
    to resize an image, you can use this:
    Code:
     Public Function ResizePic(ByVal getPicAddress As String)
    
            Try
                Dim picBox As PictureBox = Form1.PictureBox1 'pic to resize
                Dim pSizeMode As PictureBoxSizeMode = PictureBoxSizeMode.CenterImage
    
    
                picBox.Image = Nothing
                picBox.SizeMode = pSizeMode
                If System.IO.File.Exists(getPicAddress) Then
                    Dim imgOrg As Bitmap
                    Dim imgShow As Bitmap
                    Dim g As Graphics
                    Dim divideBy, divideByH, divideByW As Double
                    imgOrg = DirectCast(Bitmap.FromFile(getPicAddress), Bitmap)
    
                    divideByW = imgOrg.Width / picBox.Width
                    divideByH = imgOrg.Height / picBox.Height
                    If divideByW > 1 Or divideByH > 1 Then
                        If divideByW > divideByH Then
                            divideBy = divideByW
                        Else
                            divideBy = divideByH
                        End If
    
                        imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy))
                        imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
                        g = Graphics.FromImage(imgShow)
                        g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                        g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
                        g.Dispose()
                        'get format
    
                        Dim NewPicAddress As String = CurDir() & "\images\" & getPicAddress.Substring(getPicAddress.LastIndexOf("\") + 1)
    
                        Debug.Print(NewPicAddress)
    
                        NewPicAddress = getPicAddress.Remove(getPicAddress.Length - 3, 3)
                        imgShow.Save(NewPicAddress & "bmp", System.Drawing.Imaging.ImageFormat.Bmp)
                        'now delete old one
                        Form1.PictureBox1.ImageLocation = NewPicAddress & "bmp"
    
                    Else
                        imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
                        imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
                        g = Graphics.FromImage(imgShow)
                        g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                        g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
                        g.Dispose()
                    End If
                    imgOrg.Dispose()
    
                    picBox.Image = imgShow
    
                Else
                    picBox.Image = Nothing
    
                End If
    
    
    
                Return True
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
    
    
    
        End Function
    so, you would have an event fire (maybe, onload, or click event) that would call the above function.
    if you have any questions, let me know
    jason

  3. #3
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    452

    Re: Display list of images from internet

    the only thing you would need to change is this bit:
    vb Code:
    1. 'change this to a folder you want.  right now, this is saying it will save the new image in folder called "images" in the current directory
    2.  
    3.                     Dim NewPicAddress As String = CurDir() & "\images\" & getPicAddress.Substring(getPicAddress.LastIndexOf("\") + 1)
    4.  
    5.  
    6. 'this will save the image as a bmp
    7.                     NewPicAddress = getPicAddress.Remove(getPicAddress.Length - 3, 3)
    8.  
    9.  
    10.                     imgShow.Save(NewPicAddress & "bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    11.          
    12.                     Form1.PictureBox1.ImageLocation = NewPicAddress & "bmp"

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