简体   繁体   中英

store photo library images in cache or file path ios

单击按钮,我已经在ios中使用assestlibrary框架获取了图像,并获取了所有图像,但是单击按钮超过2-3次,由于检索到150张以上的照片,应用程序变慢或崩溃了。是否有任何代码可以我可以获取照片路径或照片库图像的缓存,以便应用程序顺利运行?

I had the same issue. In the end rather then storing the image in memory we saved the ALAssetUrl in an array. So whenever you want to work with an image you pull it out of the asset library using its url.

-(void)storeAssetInArray:(ALAsset *)asset {
    _assetArray = [[NSMutableArray alloc] init];
    [_assetArray addObject:[asset valueForProperty:ALAssetPropertyURLs]];
}

-(void)getImageBackOut {
    [ALAssetsLibrary assetForURL:[_assetArray objectAtIndex:0] resultBlock:^(ALAsset *asset) {
        if (asset) {
            [self getTheImage:uploadImage Asset:asset];
        }
    } failureBlock:^(NSError *error){
        //Failed to get asset
    } ];
}

-(void)getTheImage:(UploadImage *)uploadImage Asset:(ALAsset *)asset {
    UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM