使用 UIImagePicker 一次后出现内存警告

发布于 2024-08-13 09:04:12 字数 496 浏览 3 评论 0原文

我提到了这个非常好的参考: https://stackoverflow.com/questions/1282830/ uiimagepickercontroller-uiimage-memory-and-more 但我遇到了一些非常严重的问题。拍照后,我会收到内存警告。这是我拍摄的第一张照片,不是第二张或第三张。

我想知道是否是因为我从应用程序目录加载了几个小 jpeg 到滚动视图中。我能想到的唯一解决方案是在 UIImagePicker 处于活动状态时卸载主视图中的所有内容,然后再次重新加载所有内容,但我不确定这是否是正确的解决方案,并且我不确定如何执行此操作。

UIImagePicker 是否会占用那么多内存?我什至还没有处理或显示它所需要的图像。即使我扔掉图像,我也会收到内存警告。

任何帮助表示赞赏。

I've referred to this very good reference: https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more but I'm having some very serious issues. After I take a photo, I receive a memory warning. This is for the first photo I take, not the second or third.

I was wondering if it's because I've got a couple of small jpegs loaded from the application directory into scrolling views. The only solution I can think of is to unload everything in my mainview whilst the UIImagePicker is active, and reload everything again afterwards, but I'm not sure that's the correct solution and I'm not sure how to do that.

Does the UIImagePicker use up that much memory? I haven't even got as far as processing or displaying the image it takes yet. I get a memory warning, even if I throw the image away.

Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2024-08-20 09:04:12

对于所有仍在寻找实际答案而不是模糊陈述的人,请查看此处。我注意到有数百个答案,例如“处理你的记忆”,但这并不能回答任何问题。希望这对其他人有帮助...

将以下内容更改

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setImage:image];
    [self dismissModalViewControllerAnimated:YES];
}

为以下内容,以便在设置图像之前关闭模态视图...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self dismissModalViewControllerAnimated:YES];
    [imageView setImage:image];
}

For all the people that are still looking for the actual answer and not a vague statement then look here. I noticed there are hundreds of answers such as "Handle your memory" but that doesn't answer anything. Hope this helps someone else out there...

Change the following

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setImage:image];
    [self dismissModalViewControllerAnimated:YES];
}

To the following so your modal view dismisses before setting your image...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self dismissModalViewControllerAnimated:YES];
    [imageView setImage:image];
}
云醉月微眠 2024-08-20 09:04:12

是的,这种情况发生了。要记住的是,收到内存警告是可以的,这并不意味着你是一个坏人,你只需要确保你的应用程序不会因内存警告而崩溃或感到困惑。

特别是,您需要了解 UIViewController 的默认操作是在视图不可见时卸载其视图,并且如果显示全屏图像选择器,它们将不可见。

Yes, this happens. The thing to remember is that it's okay to get a memory warning, it doesn't mean you're a bad person, you just need to make sure that your application doesn't crash or get confused in response to the memory warning.

In particular, you need to understand that the default action of UIViewController is to unload its views if they're not visible, and they won't be visible if the full-screen image picker is showing.

旧街凉风 2024-08-20 09:04:12

最有可能的是,您正在使用未经编辑的图像,并且它们以 1400x1300 的完整尺寸返回,这很大并且会使您的应用程序崩溃,我建议将图片大小调整为 iphone 原生 320x480 分辨率,应该可以解决您的问题

Most likely you are using uneditted images, and they come back at full blown size of 1400x1300 which is huge and w ill crash your app, i suggest resizing the pictures to the iphone native 320x480 resolution, should fix your problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文