images. So I decided to do some tests to see what I can do with the results and how easy it would be in C# to load the images (it is
really easy, I was well chuffed when it all clicked into place)
string query = http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?;
query += "appid=[SOMEIDSHOULDGOHERE]&";
query += "query=" + txtQuery.Text +"&";
query += "results=5&";
query += "start=1&";
query += "format=any";
imageList = newImageList();
WebRequestwr =WebRequest.Create(query);
using(WebResponse wResp = wr.GetResponse())
{
ImageSearchResponse.ResultSet imgResp = newImageSearchResponse.ResultSet();}
using(Stream responseStream = wResp.GetResponseStream())
{XmlSerializer serializer = newXmlSerializer(typeof(ImageSearchResponse.ResultSet));}
imgResp = (ImageSearchResponse.ResultSet)serializer.Deserialize(responseStream);
//Add the images into
int imageIdx = 0;
foreach(ImageSearchResponse.ResultTypert in imgResp.Result)
{WebRequestwrImage =WebRequest.Create(rt.Url);}
using(WebResponse wRespImage = wrImage.GetResponse())
{Stream sr = wRespImage.GetResponseStream();}
System.Drawing.ImageinsertImage = Bitmap.FromStream(sr);
imageList.Images.Add(insertImage);
lstImages.Items.Add(rt.Title, imageIdx++);
lstImages.LargeImageList = imageList;
Basically the above code construct a REST Query to send to Yahoo, inside the REST Query are the parameters for the search and its results.
The WebRequest is created and the WebResonse is recieved. The Xml feed is then serialized into a custom datatype that is created from
Yahoo's schema via the xsd.exe tool.
The custom data type is then iterated across, because each item in the ImageSearchResponse.Result is an image that matches our searcg
criteria.
A new query is then created to download this image from the site that Yahoo is pointing to. The response stream is returned and an image
created directly off this via Bitmap.FromStream(); The Bitmap is then loaded into an ImageList.
Comments: [Add New]
I am making similar webrequests for images, but the requests are made to an IP camera. I continually call a method that makes a request to the camera's URL for an image and then I get the image and display it. However, I find that when I continually call the webrequest loop, I eventually throw an "out of memory" exeption. I haven't figured out where I'm not getting things cleaned up. Have you run into this?
