Images from url to listview
Posted
by
Andres
on Stack Overflow
See other posts from Stack Overflow
or by Andres
Published on 2012-10-11T20:40:00Z
Indexed on
2012/10/11
21:37 UTC
Read the original article
Hit count: 214
I have a listview which I show video results from YouTube. Everything works fine but one thing I noticed is that the way it works seems to be a bit slow and it might be due to my code. Are there any suggestions on how I can make this better? Maybe loading the images directly from the url instead of using a webclient?
I am adding the listview items in a loop from video feeds returned from a query using the YouTube API. The piece of code which I think is slowing it down is this:
Feed<Video> videoFeed = request.Get<Video>(query);
int i = 0;
foreach (Video entry in videoFeed.Entries)
{
string[] info = printVideoEntry(entry).Split(',');
WebClient wc = new WebClient();
wc.DownloadFile(@"http://img.youtube.com/vi/" + info[0].ToString() + "/hqdefault.jpg", info[0].ToString() + ".jpg");
string[] row1 = { "", info[0].ToString(), info[1].ToString() };
ListViewItem item = new ListViewItem(row1, i);
YoutubeList.Items.Add(item);
imageListSmall.Images.Add(Bitmap.FromFile(info[0].ToString() + @".jpg"));
imageListLarge.Images.Add(Bitmap.FromFile(info[0].ToString() + @".jpg"));
}
public static string printVideoEntry(Video video)
{
return video.VideoId + "," + video.Title;
}
As you can see I use a Webclient which downloads the images so then I can use them as image in my listview. It works but what I'm concerned about is speed..any suggestions? maybe a different control all together?
© Stack Overflow or respective owner