iPhone保存多个视图截图

发布于 2024-09-09 05:27:43 字数 520 浏览 3 评论 0原文

我有一个 UIImagePickerController,向其中添加一些包含图像的子视图。我需要将整个内容保存为图像,但未能做到这一点。

为了保存上下文的内容,我使用以下代码

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

它适用于 UIImagePickerController 但如果我添加子视图,它会停止在

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

行,没有任何控制台出现错误,只需退出应用程序即可。

谢谢!

I have an UIImagePickerController to which I add some subviews that contain images. I need to save the whole content as an image, but fail to do this.

For saving the content of the context i use the following code

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It works for the UIImagePickerController but if i add subviews it stops at the

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

line, without any error in the console, just quits the app.

Thanks!

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

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

发布评论

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

评论(1

临走之时 2024-09-16 05:27:43

如果您试图抓取屏幕截图中屏幕上的所有内容,我在堆栈溢出中发现了这一点:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

它将抓取窗口上的所有内容。

希望这有帮助。

If you are trying to grab everything on the screen in your screen shot, I found this on stack overflow:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It will grab everything on the window.

Hope this helps.

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