If I have an array of urls which link to images, how can I list them as thumbnails in my application?
Printable View
If I have an array of urls which link to images, how can I list them as thumbnails in my application?
is your question about the array part, picturebox part, or the resize part?
to assign a picture box a url, use this code:
to resize an image, you can use this:Code:Me.PictureBox1.ImageLocation = "http://someaddress/somepic.jpg"
so, you would have an event fire (maybe, onload, or click event) that would call the above function.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
if you have any questions, let me know
jason
the only thing you would need to change is this bit:
vb Code:
'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 Dim NewPicAddress As String = CurDir() & "\images\" & getPicAddress.Substring(getPicAddress.LastIndexOf("\") + 1) 'this will save the image as a bmp NewPicAddress = getPicAddress.Remove(getPicAddress.Length - 3, 3) imgShow.Save(NewPicAddress & "bmp", System.Drawing.Imaging.ImageFormat.Bmp) Form1.PictureBox1.ImageLocation = NewPicAddress & "bmp"