iPhone:UIImagePickerController 各种问题

发布于 2024-07-30 12:36:11 字数 1272 浏览 1 评论 0原文

各位 stackoverflow 的优秀人员大家好!

我有个问题。

我正在开发一个应用程序,它将拍摄多张照片,每次都会放大它们,显示预览,保存它们,然后再次加载 UIImagePickerController。

但拍了大约5到6张照片后它就死了。

我认为它快要死了,因为我设置了一个 UIImageView,并且在看了这么多图片之后,我设置它的 UIImage 不再引用任何内容。

我认为罪魁祸首就在这里……

我做错了什么吗?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [backgroundImage setImage: [[UIImage alloc] initWithCGImage:[[info objectForKey:UIImagePickerControllerOriginalImage] CGImage]]];
    [backgroundImage setTransform:CGAffineTransformRotate(CGAffineTransformMakeScale(zoom/3, zoom/3), 1.570796327)];

    UIGraphicsBeginImageContext([backgroundView bounds].size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextFillRect(ctx, [backgroundView bounds]);
    [backgroundView.layer renderInContext:ctx];
    UIImage* screenImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(screenImage, self, @selector(ImageDidSave:didFinishSavingWithError:contextInfo:), nil);

    [self dismissModalViewControllerAnimated:YES];
}

backgroundImage 是最终尝试使用不再引用任何内容的图像的图像。

让我知道如何澄清。

非常感谢迄今为止陪伴我的所有人!

Hello wonderful people of stackoverflow!

I have a problem.

I am working on an app that will take multiple photos and each time it will enlarge them, show a preview, save them, and then load the UIImagePickerController again.

But after taking about 5 to 6 pictures it dies.

I think that it is dying because I have a UIImageView that I set and after so many pictures the UIImage that I set it with is no longer referencing anything.

I think that the culprit is somewhere in here...

Is there something that I am doing wrong?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [backgroundImage setImage: [[UIImage alloc] initWithCGImage:[[info objectForKey:UIImagePickerControllerOriginalImage] CGImage]]];
    [backgroundImage setTransform:CGAffineTransformRotate(CGAffineTransformMakeScale(zoom/3, zoom/3), 1.570796327)];

    UIGraphicsBeginImageContext([backgroundView bounds].size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextFillRect(ctx, [backgroundView bounds]);
    [backgroundView.layer renderInContext:ctx];
    UIImage* screenImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(screenImage, self, @selector(ImageDidSave:didFinishSavingWithError:contextInfo:), nil);

    [self dismissModalViewControllerAnimated:YES];
}

backgroundImage is the one that eventually tries to use an image that is no longer referencing anything.

Let me know how I can clarify.

Thank you very much everyone who stayed with me this far!

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

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

发布评论

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

评论(1

难如初 2024-08-06 12:36:11

这是一个猜测,但我敢打赌你的内存即将耗尽并被杀死。 尝试在这一行中自动释放发送到后台的图像:

[backgroundImage setImage: [[[UIImage alloc] initWithCGImage:[[info objectForKey:UIImagePickerControllerOriginalImage] CGImage]] autorelease]];

This is a guess, but I bet you're running out of memory and being killed. Try autoreleasing the image you send to the background in this line:

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