. Topicala Page Index Token

A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!

I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.

Quick Search

Web www.kinlan.co.uk

Sunday, May 15, 2005

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 for
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);
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

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?

By Anonymous, at Tuesday, September 05, 2006 6:11:00 PM