iphone - 使用 UIImagePickerControllerReferenceURL 在 UIImageView 上设置图像

标签 iphone uiimageview

是否可以使用 UIImageView 设置图像 UIImagePickerControllerReferenceURL 。传统的模式是使用 [信息 objectForKey:@"UIImagePickerControllerOriginalImage"];

I tried this:

theImageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[info objectForKey:UIImagePickerControllerReferenceURL]]];

但是 UIImageView 上没有设置图像。

请帮忙。

最佳答案

NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library assetForURL:referenceURL resultBlock:^(ALAsset *asset)
         {
           UIImage  *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
             theImageView.image = copyOfOriginalImage;
         }
                failureBlock:^(NSError *error)
         {
             // error handling
         }];
        [library release];

这段代码成功了。 :)

关于iphone - 使用 UIImagePickerControllerReferenceURL 在 UIImageView 上设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8343557/

相关文章:

iphone - 在 iOS 应用程序中使用 mod 运算符

iphone - 3.0.1 更新后配置 iPhone 时出现问题

iphone - iOS 基本 FTP 设置;读写流

iPhone:在循环中创建 NSString 时出现巨大的内存峰值

ios - 横向图像拉伸(stretch)如何解决?

ios - 将 UIImage 定位在 UIScrollView 的中心进行缩放

ios - ios 7 中的自定义 leftBarButtonItem 问题

ios - 如何在不使用另一个 UIImage 的情况下屏蔽 UIImageView,只是简单地定义一个简单的形状,如圆角正方形?

ios - 如何在 iOS 中保存 UIImageView 数据

ios - [UICollectionViewCell cellImageView] : unrecognized selector sent to instance