Image Processing: Part 1

I get so many things running through my head that I want to do. I was looking at the Yahoo search API and I found that you can search forimages. 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 isreally 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 fromYahoo'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 searcgcriteria.

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 imagecreated directly off this via Bitmap.FromStream(); The Bitmap is then loaded into an ImageList.

About Me: Paul Kinlan

I lead the Chrome Developer Relations team at Google.

We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.

Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on web.dev, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.