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

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

问题描述

我正在尝试用我的应用程序拍照,然后在我的.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 *)选择器didFinishPickingImage:(UIImage *)图像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的Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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