【问题标题】:Adding Images To UIImageView将图像添加到 UIImageView
【发布时间】:2013-11-14 00:00:49
【问题描述】:

在数据库中,我有一个图像路径列表,路径如下所示。

assets-library://asset/asset.JPG?id=94473FB8-A6CE-4775-9C57-B8350B335E2B&ext=JPG

我正在尝试采用该路径并使用它加载图像。但是 graphImage 返回 nil 并且图像路径不是 nil。

如何将带有路径的图像加载到单元格的 UIImageView 中?

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView     cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{


     NSString *imagePath  = [array_photos objectAtIndex:[indexPath row]];
     UIImage  *graphImage = [[UIImage alloc] initWithContentsOfFile: imagePath];

     cell.photoImageView.image = graphImage;



}

【问题讨论】:

    标签: objective-c uiimage


    【解决方案1】:

    由于您拥有的路径是用于资产库(也就是您的 iPhone 的照片库),因此您需要以不同的方式加载它们。使用ALAssetsLibrary

    - (void)assetForURL:(NSURL *)assetURL resultBlock:(ALAssetsLibraryAssetForURLResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock
    

    确保在您的项目中包含AssetsLibrary.framework

    【讨论】:

    • 是的,看起来像你的权利!实施是另一回事。感谢您向前迈出的一步。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多