rakendu
rakendu

Reputation: 77

iphone retrieve image using URL using ALAsset

I want to know how to how to retrieve a image using URL. I am using the ALAsset. I followed the answer (the one with the tick mark) from the following link display image from URL retrieved from ALAsset in iPhone. How to retrieve the image and upload it?

Upvotes: 6

Views: 10593

Answers (3)

Dannie P
Dannie P

Reputation: 4622

Check out this method

+ (UIImage *)imageFromAsset:(ALAsset *)asset
{
    ALAssetRepresentation *representation = [asset defaultRepresentation];
    return [UIImage imageWithCGImage:representation.fullResolutionImage
                               scale:[representation scale]
                         orientation:(UIImageOrientation)[representation orientation]];
}

I've slightly adjusted it based on this gist: https://gist.github.com/NR4TR/8576048

Upvotes: 2

user1369511
user1369511

Reputation: 211

I know this is an old question but just in case anyone else comes I found another method (requires iOS 5+) that returns an easier to work with image:

UIImage *img = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] 
               fullScreenImage];


From the docs of fullScreenImage:

In iOS 5 and later, this method returns a fully cropped, rotated, and adjusted image—exactly as a user would see in Photos or in the image picker.

monkybonk05's answer does work, but it not cropped or rotated.

Upvotes: 3

Mike
Mike

Reputation: 2409

Have you managed to get the ALAsset? Once you do, getting the image is easy. To get a thumbnail, the asset has a method...thumbnail.

UIImage *img = [UIImage imageWithCGImage:[myAsset thumbnail]];

To get the full Res image you have to go through the default representation.

UIImage *img = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] fullResolutionImage]

Hope this helps

Upvotes: 16

Related Questions