UIImageView 不显示来自 UIImagePickerController 的图像 [英] UIImageView does not show Image from UIImagePickerController

查看:24
本文介绍了UIImageView 不显示来自 UIImagePickerController 的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用我的应用程序拍照,然后在我的 .xib 中预定义的 UIImageView 中显示它.我有一个 IBOutlet UIImageView *_foto 链接到 .xib 中的 UIImageView

I am trying to take a picture with my app and then show it in a UIImageView that is predefined in my .xib. I have a IBOutlet UIImageView *_foto that is linked to the UIImageView in the .xib

当我执行以下操作时,拍照后 UIImageView 中不显示图片:

When I do the following the picture doesnt show in the UIImageView after taking a picture:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
    {

        _foto.image = image;
        //Also tried set image, and resizing the image first

        [self dismissModalViewControllerAnimated:YES];

    }

现在,当我添加代码以使用从我的选择器返回的图像创建一个新的图像视图,并将其作为子视图添加到我的视图中时,会发生一些奇怪的事情:

Now, when I add code to create a new image view with the image returned from my picker, and add that as a subView to my view like this, something strange happens:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{


    UIImageView *iv = [ [UIImageView alloc] initWithImage:image];

    [self.view addSubview:iv];

    [iv release];

    _foto.image = image;

    [self dismissModalViewControllerAnimated:YES];
}

现在图像显示在我的视图左上角新创建的图像视图中,正如预期的那样,但也显示在我的_foto UIImageView中.这让我很困惑,我不知道发生了什么,我只知道这不是我所期望的行为.有没有人有任何线索,希望能找到解决这个问题的正确方法?

Now the image shows in both the newly created image view in the left top corner of my view,as expected, but also in my _foto UIImageView. This has me seriously confused, and I have no idea what is going on, all i know is that it is not the behavior i expected. Does anyone have any clue, and hopefully a proper solution for this problem?

推荐答案

UIImagePickerController 在选择图像时会占用大量设备内存.在 - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 我注意到很多次内存警告级别 1 和 2.它可能会导致强制卸载并重新加载您的视图,再次启动视图控制器的 viewDidLoad 方法.如果您的 _foto 对象是一个 IBOutlet ,它将从内存中删除并再次加载所有属性的起始值(图像也是).此外,如果您在 viewDidLoad 中将 image 设置为 nil,这可能是一个原因.

UIImagePickerController grab a lot of device memory while picking an image. During - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo I've noticed many times memory warnings level 1 and 2. It may cause force unload and reload your view, launch viewDidLoad method of your view controller again. If your _foto object is an IBOutlet it will be removed from memory and load again with start values of all properties (image too). Also if you set image to nil in viewDidLoad it may be a reason.

将一些 NSLog 放入 viewDidLoad 以检查它是否重新启动.您也可以尝试将捕获的图像放入库中 - 如果库中存在图像,则问题可能在于视图卸载.

Put some NSLog into viewDidLoad to check out if it is relaunched. Also you may try to put captured image into library - if image exists in library the problem probably is in view unloading.

这篇关于UIImageView 不显示来自 UIImagePickerController 的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆