使用关键字从flickr下载随机图像

时间:2009-05-04 18:04:26

标签: c# api download flickr

当我在使用smallbasic时,我注意到这段代码显示它有一个内置选项,可以根据关键字从fliker下载图像

我想知道是否有人在C#中有一个例子,以便我可以了解如何使用api。

2 个答案:

答案 0 :(得分:2)

我从来没有搞过Flickr的API,但是我发现这里的链接似乎非常有帮助:

http://blogs.msdn.com/coding4fun/archive/2006/11/22/1126978.aspx

答案 1 :(得分:2)

private void button1_Click(object sender, EventArgs e)
{
    string apikey = "3f8554b23a5we2fe2c7asdg80agnkdm9cedag415f34d9fb";
    Flickr F = new Flickr(apikey);


    // Example 2
    PhotoSearchOptions searchOptions = new PhotoSearchOptions();
    searchOptions.Tags = textBox1.Text;
    searchOptions.PerPage = 100;
    Photos microsoftPhotos = F.PhotosSearch(searchOptions);

    // Example 3
    searchOptions.Page = 2;
    Photos microsoftPhotos2 = F.PhotosSearch(searchOptions);
    searchOptions.Page = 3;
    Photos microsoftPhotos3 = F.PhotosSearch(searchOptions);

    // Eample 4
    PhotoCollection allPhotos = microsoftPhotos.PhotoCollection;
    allPhotos.AddRange(microsoftPhotos2.PhotoCollection);
    allPhotos.AddRange(microsoftPhotos3.PhotoCollection);


    progressBar1.Maximum = allPhotos.Count;
    progressBar1.Value = 0;


    foreach (Photo p in allPhotos)
    {
        pictureBox1.Image = Image.FromStream(F.DownloadPicture(p.MediumUrl));

        this.Refresh();

        progressBar1.Value++;
    }
}