display image from URL retrieved from ALAsset in iPhone

后端 未结 4 1657
忘掉有多难
忘掉有多难 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:41

    Just to combine Warren's and oknox's answers into a shorter snippet:

    ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
    [assetsLibrary assetForURL:self.selectedPhotos[i] resultBlock: ^(ALAsset *asset){
        ALAssetRepresentation *representation = [asset defaultRepresentation];
        CGImageRef imageRef = [representation fullResolutionImage];
        if (imageRef) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
            imageView.image = [UIImage imageWithCGImage:imageRef scale:representation.scale orientation:representation.orientation];
            // ...
        }
    } failureBlock: ^{
        // Handle failure.
    }];
    

    I personally like setting my failureBlock to nil.

提交回复
热议问题