首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >图像不显示表单UIImagePickerControllerReferenceURL图像路径

图像不显示表单UIImagePickerControllerReferenceURL图像路径
EN

Stack Overflow用户
提问于 2014-03-27 16:34:08
回答 2查看 257关注 0票数 1

我使用UIImagePickerControllerReferenceURL从图片库中选择了图像,我得到了图像路径,并分配给imageView.image仍然不显示该图像,下面是我的代码。

代码语言:javascript
运行
复制
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

  NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];     
  ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset) {

        ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];

        NSString *homeDirectoryPath = NSHomeDirectory();
        NSString *imagName = [imageRep filename];
        NSString *imagePath = [homeDirectoryPath stringByAppendingString:imagName];

        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,40,40)];
        imageView.image= [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]]];

        UIView *aView=[[UIView alloc]initWithFrame:CGRectMake(100,100,100,50)];
        aView.backgroundColor=[UIColor lightGrayColor];

        [aView addSubview:imageView];
        [categoryDisplayScrollView addSubview:aView];
        [self dismissViewControllerAnimated:YES completion:NULL];

      };

  ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
  [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];

}
EN

回答 2

Stack Overflow用户

发布于 2014-03-27 17:08:29

您可以使用UIImagePickerControllerOriginalImage获取图像。

代码语言:javascript
运行
复制
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
        UIImage *imagepicked = [info objectForKey:UIImagePickerControllerOriginalImage];

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset) {

        ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];

        NSString *homeDirectoryPath = NSHomeDirectory();
        NSString *imagName = [imageRep filename];
        NSString *imagePath = [homeDirectoryPath stringByAppendingString:imagName];

        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,40,40)];
        imageView.image= imagepicked;

        UIView *aView=[[UIView alloc]initWithFrame:CGRectMake(100,100,100,50)];
        aView.backgroundColor=[UIColor lightGrayColor];

        [aView addSubview:imageView];
        [categoryDisplayScrollView addSubview:aView];
        [self dismissViewControllerAnimated:YES completion:NULL];

      };

     ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
     [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];

 }

希望这对你有帮助...!

票数 0
EN

Stack Overflow用户

发布于 2014-03-27 18:29:26

代码语言:javascript
运行
复制
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo (NSDictionary *)info
{
    UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
}

正如在上面的代码中提到的,你可以使用UIImagePickerControllerOriginalImage键从info字典中获取UIImage。

下一步是将此UIImage分配给UIImageView。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22682095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档