|
-
Jun 6th, 2010, 01:14 PM
#1
Thread Starter
Member
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?
-
Jun 7th, 2010, 01:42 PM
#2
Hyperactive Member
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
-
Jun 7th, 2010, 01:46 PM
#3
Hyperactive Member
Re: Display list of images from internet
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"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|