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.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>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)<p /><p style="COLOR: #000000;"> <span style="COLOR: #0000ff;">string</span> <span style="">query = <a href="http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?"><a href="http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?">http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?</a></a>;</span> query += "appid=[SOMEIDSHOULDGOHERE]&"; query += "query=" + txtQuery.Text +"&"; query += "results=5&"; query += "start=1&"; query += "format=any"; imageList = <span style="COLOR: #0000ff;">new</span><span style="COLOR: #000080;">ImageList</span>(); <span style="COLOR: #000080;">WebRequest</span><span style="">wr =</span><span style="COLOR: #000080;">WebRequest</span>.Create(query); <span style="COLOR: #0000ff;">using</span><span style="">(</span><span style="COLOR: #000080;">WebResponse</span> wResp = wr.GetResponse()) {</p><blockquote style="MARGIN-RIGHT: 0px;">ImageSearchResponse.<span style="COLOR: #000080;">ResultSet</span> <span style="">imgResp =</span> <span style="COLOR: #0000ff;">new</span><span style="">ImageSearchResponse.</span><span style="COLOR: #000080;">ResultSet</span>(); <span style="COLOR: #0000ff;">using</span><span style="">(</span><span style="COLOR: #000080;">Stream</span> responseStream = wResp.GetResponseStream()) {<blockquote style="MARGIN-RIGHT: 0px;"> <span style="COLOR: #000080;">XmlSerializer</span> <span style="">serializer =</span> <span style="COLOR: #0000ff;">new</span><span style="COLOR: #000080;">XmlSerializer</span><span style="">(</span><span style="COLOR: #0000ff;">typeof</span><span style="">(ImageSearchResponse.</span><span style="COLOR: #000080;">ResultSet</span>)); imgResp = (ImageSearchResponse.<span style="COLOR: #000080;">ResultSet</span>)serializer.Deserialize(responseStream); </blockquote>} //Add the images into <span style="COLOR: #0000ff;">int</span> imageIdx = 0; <span style="COLOR: #0000ff;">foreach</span><span style="">(ImageSearchResponse.</span><span style="COLOR: #000080;">ResultType</span><span style="">rt</span> <span style="COLOR: #0000ff;">in</span> imgResp.Result) { <blockquote style="MARGIN-RIGHT: 0px;"> <span style="COLOR: #000080;">WebRequest</span><span style="">wrImage =</span><span style="COLOR: #000080;">WebRequest</span>.Create(rt.Url); <span style="COLOR: #0000ff;">using</span><span style="">(</span><span style="COLOR: #000080;">WebResponse</span> wRespImage = wrImage.GetResponse()) {<blockquote style="MARGIN-RIGHT: 0px;"> <span style="COLOR: #000080;">Stream</span> sr = wRespImage.GetResponseStream(); System.Drawing.<span style="COLOR: #000080;">Image</span><span style="">insertImage =</span> <span style="COLOR: #000080;">Bitmap</span>.FromStream(sr); imageList.Images.Add(insertImage);</blockquote>} </blockquote> } lstImages.Items.Add(rt.Title, imageIdx++);</blockquote><span style="">}</span> lstImages.LargeImageList = imageList;<p />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.<p /> The custom data type is then iterated across, because each item in the ImageSearchResponse.Result is an image that matches our searcgcriteria. <p />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 <em>Bitmap.FromStream();</em> The Bitmap is then loaded into an ImageList.</p>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2005-05-15T00:00:00+00:00) Image Processing: Part 1. Retrieved from https://www.scien.cx/2005/05/15/image-processing-part-1/

MLA
" » Image Processing: Part 1." Paul Kinlan | Sciencx - Sunday May 15, 2005, https://www.scien.cx/2005/05/15/image-processing-part-1/
HARVARD
Paul Kinlan | Sciencx Sunday May 15, 2005 » Image Processing: Part 1., viewed ,<https://www.scien.cx/2005/05/15/image-processing-part-1/>
VANCOUVER
Paul Kinlan | Sciencx - » Image Processing: Part 1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2005/05/15/image-processing-part-1/
CHICAGO
" » Image Processing: Part 1." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2005/05/15/image-processing-part-1/
IEEE
" » Image Processing: Part 1." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2005/05/15/image-processing-part-1/. [Accessed: ]
rf:citation
» Image Processing: Part 1 | Paul Kinlan | Sciencx | https://www.scien.cx/2005/05/15/image-processing-part-1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.