UIImageView Image from NSURLConnection - iphone

I have a function that retrieves some images from a JSON feed using NSURLConnection. My connectionDidFinishLoading retrieves an array with all the data for that image (including the URL of the image).
What's the best way to display that image on a UIImageView? Even though the URL is being retrieved, I am pretty sure I would still have to display the image in a connection-friendly manner?
Thank you,

As per your requirement Images must be display in connection friendly manner. Then you can go for Image cacheing which requires image URLs. For your best understanding see this link and this link.
for asynchronous image downloading try with this link.

Related

create a UIImage from points

I have a UIWebView which has images in it, say that I have the point/coordinates of the x y position of the image, width and height. Can I create an image just by specifying the location of the image in UIWebView? If yes how?
Or is there a way to get an UIImage from a UIWebView without actually looking at the <img src=""> of the html tags? Basically I don't want to make a connection to the internet to pull an image as the image is already there seen on the screen. Question is how do I extract it?
Depending on the cache policy in place, a request to retrieve the image may not result in another connection to download the image... But to answer your actual question...
You can take a 'snapshot' of the UIWebView and then crop to the location of the image in question. Check this question out for details on how to do this: How Do I Take a Screen Shot of a UIView?
This link explain a way to get the image just by grabbing it from the specified coordinates. How to create a UIImage from the current graphics context?.
However there might be a more elegant solution of using some javascript to get the original image by using the stringByEvaluatingJavaScriptFromString: method of UIWebview. But I am not sure if javascript is capable of doing it

how to download photos from remote server to iphone app?

My situation is that I am making a uitableviewcontroller with uitableviewcells having a thumb nail or picture on the left, text on the right. All data is stored in a remote server. I have made a php to communicate with backend batabase and generate JSON to pass the data to iphone through http. However, I don't know how to do the same thing to photos. Please suggest me someway to do it. Thanks!
As Mundi said it already.
And make sure that you load them asynchronously.
There is a nice tutorial on this page:
http://www.markj.net/iphone-asynchronous-table-image/
I assume you are using NSURLConnection to fetch your data from the server. Do this:
Collect the photo data into an NSData object.
In the didFinishLoading method use this to create the images:
UIImage *thumbnailImage = [[UIImage alloc] initWithData:downloadedData];
// don't forget to discard the downloaded Data and release the image
The actual setup of your cells might be more complicated. The way I do it is to check in each call to cellForRowAtIndexPath: if I have cached the image, if not I pass to URL of the image to a NSURLConnection. I keep the open connections in an array and eliminated them when each download finishes or the view disappears. Let me know if you need more hints...

Lazy loading thumbnail images

I am trying to lazily load a dynamic thumbnail view.
I have to put images in thumbnail view one by one and until images are not available I have to display temporary image like placeholder. Any guidelines please?
See the accepted answer in this thread. You wouldn't need the last-in first-out stack, but it shows how to load images asynchronously using grand central dispatch, which is quite straightforward. You don't need to think about complicated thread management. :)
You could go about like this -
Create a UIImageView with a default placeholder image.
Fetch your image in a background thread. You want to do it like this
because, fetching image in the main UI thread blocks it till the
image is fetched, which severely hampers UI responsiveness. There
are several libraries available which do this for you. They even
cache the images. SDWebImage is great!
See if you get a valid HTTP 200 response back i.e. a valid image. If yes, then replace the new image with placeholder image. Else let the placeholder image be.
Hope this helps...

How does One place an image inside of an image using metadata?

For example, I can convert the second image into NSData and then place it inside metadata inside the first image and then when I open the first image and read the metadata I can get the NSData and turn it into an UIImage.
How would I go about doing this? All the metadata tags I see are not large enough to support another picture. I know picture in picture is quite common on desktop apps so I'm interested in getting it to work on the iPhone.
Is metadata the correct way to do this or is there another way?

iPhone - access location information from a photo

Is it possible, in an iPhone app, to extract location information (geocode, I suppose it's called) from a photo taken with the iPhone camera?
If there is no API call to do it, is there any known way to parse the bytes of data to extract the information? Something I can roll on my own?
Unfortunately no.
The problem is thus;
A jpeg file consists of several parts. For this question the ones we are interested in are the image data and the exif data. The image data is the picture and the exif data are where things like geocoding, shutter speed, camera type and so on are stored.
A UIImage (and CGImage) only contain image data, no tags.
When the image picker selects an image (either from the library or the camera) it returns a UIImage, not a jpeg. This UIImage is created from the jpeg image data, but the exif data in the jpeg is discarded.
This means this data is not in the UIImage at all and thus is not accessible.
I think the selected answer is wrong, actually. Well, not wrong. Everything it said is correct, but there is a way around that limitation.
UIImagePickerController passes a dictionary along with the UIImage it returns. One of the keys is UIImagePickerControllerMediaURL which is "the filesystem URL for the movie". However, as noted here in newer iOS versions it returns a url for images as well. Couple that with the exif library mentioned by #Jasper and you might be able to pull geotags out of photos.
I haven't tried this method, but as #tomtaylor mentioned, this has to be possible somehow, as there are a few apps that do it. (e.g. Lab).