views:

677

answers:

2

Hey all,

I noticed this code when i was playing around with smallbasic showing it to a freind that it has a built in option to download a image from fliker based on a keyword

I was wondering if someone had an example in C# of doing this so that i can get an idea of how to use the api.

+2  A: 

I've never messed with Flickr's API, but here's a link I found that seems like it would be pretty helpful:

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

BFree
so far so goodI have my api key and im using the flikr.dll but still now sure how to display the images i find
Crash893
+1  A: 
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++;
    }
}
Crash893
Im working on makeing the foreach loop multithreaded any ideas?
Crash893
Use BackgroundWorker to do the MT: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx.
Erich Mirabal
wouldnt that just do the same thing but seperate it from the main thread?it would do 2 at once only 1 at a time and i would still be able to use the gui
Crash893
Well, depending on how easy or hard you want to make it, you can either create a new BW for each photo to download on its own thread or throw them on the ThreadPool as work items. The BW gives you a bit more control and information. If you want to only download a couple at a time, add the times to a queue, use BW, and do that. You would basically create your own ThreadPool, but with more info and better support for UI integration.
Erich Mirabal
I'll keep that in mind. My proof of concept app was something that would download the first 500 images what ever keyword you pick then blast them by the screen super fast( it was just a joke on the word flicker) my long term goal is to integrate it with my wallpaper changer to download a random image from flicker based on keywords the user inputs and display it.the question about multithreading should amost be a diffrent question becuase it doesnt directly affect the question. Do you know if and when parellel.foreach will be included in the express editions?
Crash893