Is there any way that I can let the user select an image from a google images search and convert it into a UIImage?
A:
Off the top of my head you could do it like this:
- Do the Google search in your own UIWebView
- Use the UIWebViewDelegate to respond to requests, and filter for the the Google image requests
- Parse that URL to isolate the source image
- Use NSUrlRequest to get the image
- Feed the response data in to a UIImage
There may be a more efficient way, but this seems like a relatively simple way you could do it.
Chris Blackwell
2010-10-25 22:04:12
I could probably work out how to do the google search (I have never used UIWebView before, but it can't be too hard). How would I do the rest? Sorry for my idiocy
Daniel Thatcher
2010-10-27 09:47:42
I'm not sure how familiar you are with iOS/objective-c programming, but I'll assume you're familiar with delegates (if not, you should get familiar with them.) You'll need a class (typically the encompassing view) to be a delegate for the UIWebView. The method of interest is webView:shouldStartLoadWithRequest:navigationType: which will be called whenever navigation is attempted. This will pass an NSURLRequest parameter which will contain the text of the URL. Google image search URL's contain the original URL, so you'll need to parse that out with string utils
Chris Blackwell
2010-10-27 17:51:00
Then once you've done that, you can just take that URL and load it with an HTTP request via NSUrlRequest. The return value (again done with delegates) will contain the image, and you create an image with the UIImage:imageWithData initializer. That should point you in the right direction without me actually having to code it all :)
Chris Blackwell
2010-10-27 17:56:14