Retrieve members avatar
Guides, Help & Support, Tutorials and Examples on how to access and use the Site API.
1 post
Page 1 of 1
Hello,
This is a quick function to help get a members avatar image when displaying things like status messages and friends.
It checks to see if an avatar image already exits in a local folder and if not it downloads and saves the avatar as a thumbnail into the folder. If the avatar already exists then it uses the image from the local folder which helps display content faster because you dont need to load the images from the web all the time.
Firstly you will want to check/create the folder to store the avatars in:
This is a quick function to help get a members avatar image when displaying things like status messages and friends.
It checks to see if an avatar image already exits in a local folder and if not it downloads and saves the avatar as a thumbnail into the folder. If the avatar already exists then it uses the image from the local folder which helps display content faster because you dont need to load the images from the web all the time.
Firstly you will want to check/create the folder to store the avatars in:
Code: Select all
Then the function:If Not My.Computer.FileSystem.DirectoryExists(Application.StartupPath & "\Avatars\") Then
My.Computer.FileSystem.CreateDirectory(Application.StartupPath & "\Avatars\")
End If
Code: Select all
Then to use it you just pass in the avatar url and members username: Public Function AvatarIMG(ByVal Avatar As String, ByVal Username As String)
If Avatar Is Nothing Or Username Is Nothing Then
Return Nothing
Else
If Not My.Computer.FileSystem.FileExists(Application.StartupPath & "\Avatars\" & Username & ".png") Then
Using WebC As New Net.WebClient()
Dim Thumb = Image.FromStream(WebC.OpenRead(Avatar.Replace("./download/file.php", "http://www.codenstuff.com/forum/download/file.php")))
Thumb.GetThumbnailImage(45, 45, Function() False, Nothing).Save(Application.StartupPath & "\Avatars\" & Username & ".png")
Thumb.Dispose()
Return Application.StartupPath & "\Avatars\" & Username & ".png"
End Using
Else
Return Application.StartupPath & "\Avatars\" & Username & ".png"
End If
End If
End Function
Code: Select all
Example loading into a picturebox:AvatarIMG(item.avatar, item.name)
Code: Select all
Works well enough cooll;Picturebox.LoadAsync(AvatarIMG(item.avatar, item.name))
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023