gpt4 book ai didi

ios - iOS-显示来自“ALAssetLibrary”的图片

转载 作者:行者123 更新时间:2023-12-01 18:52:19 24 4
gpt4 key购买 nike

我有ViewController1ViewController2ViewController1UICollectionView,它使用ASAssetLibrary将缩略图加载到UICollectionViewCell中:

NSMutableArray *collector = [[NSMutableArray alloc] initWithCapacity:0];
ALAssetsLibrary *al = [TemplateEditBarController defaultAssetsLibrary];
[al enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset) {
[collector addObject:asset];
}
}];
assetsarray = collector;//<--assetsarray is local.
}
failureBlock:^(NSError *error) { NSLog(@"fail!");}
];

选择 cell时,我想将 NSStringNSURL传递给 ViewController2,以便它将调用并显示全分辨率图像。但是当 NSLog网址时:
ALAsset* asset = backgroundsarray[row];
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSURL *url = [representation url];
newbg = [url absoluteString];//<-NSLog this.

我得到:

asset-library://asset/asset.JPG?id = 6E5438ED-9A8C-4ED0-9DEA-AB2D8F8A9360&ext = JPG

我尝试更改为得到的 [url path]:

asset.JPG

如何获取实际的照片网址,以便可以转换为 NSString并传递给 ViewController2

最佳答案

NSURL* aURL = [NSURL URLWithString:imagePath];        
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:aURL resultBlock:^(ALAsset *asset)
{
UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage] scale:0.5 orientation:UIImageOrientationUp];
imageView.image=image;

}
failureBlock:^(NSError *error)
{
// error handling
NSLog(@"failure-----");
}];

关于ios - iOS-显示来自“ALAssetLibrary”的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30205554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com