display image from URL retrieved from ALAsset in iPhone

后端 未结 4 1604
忘掉有多难
忘掉有多难 2020-11-22 12:39

I am using a ALAsset Framework for accessing the files in the device\'s photo gallery.

So far I am able to access the thumbnail and display it.
I want to display

4条回答
  •  死守一世寂寞
    2020-11-22 13:27

    Warren's answer worked well for me. One useful thing for some people is to include the image orientation and scale metadata at the same time. You do this in your result block like so:

    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        ALAssetRepresentation *rep = [myasset defaultRepresentation];
        CGImageRef iref = [rep fullResolutionImage];
        if (iref) 
        {
            UIImage *largeimage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:[rep orientation]];
            [delegate hiresImageAvailable:large];
        }
    };
    

    The imageWIthCGImage call in that case has scale and orientation added when it creates a UIImage for you.

    [UIImage imageWithCGImage:iref scale:[rep scale] orientation:[rep orientation]];
    

    One trick to note is that if you use [rep fullScreenImage] instead of [rep fullResolutionImage] on iOS 5 you get an image that is already rotated - it is however at the resolution of the iPhone screen - i.e. its at a lower resolution.

提交回复
热议问题