需要在运行时创建视图的快照
我需要拍摄当前 ipad 视图的快照。该视图加载并播放视频。 我发现这个功能几乎非常有效。
- (UIImage*)captureView:(UIView *)view {
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
(来源:LINK )
问题是,播放视频的当前帧没有被捕获,只有视图,但没有视频内容。在保存图像之前我是否忘记更新显示或其他内容?是否有读取最新屏幕值的特殊功能?
感谢您的时间和帮助。
i need to take a snapshot of my current ipad-view. That view loads and plays a video.
I found this function which works almost really well.
- (UIImage*)captureView:(UIView *)view {
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
(Source from: LINK)
The problem is, that the current frame of the playing video is not captured, only the view but without video-content. Do i forgot to update the display or anything else before saving the image? Is there a special function that reads the latest screen-values?
Thanks for your time and help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用UIGetScreenImage()函数?
它是私有的,但 Apple 允许使用它,因此即使您使用它,您的应用程序也会在 App Store 中进行验证。
你只需要声明它的原型,这样编译器就不会抱怨:
注意:你可以使用以下 NSImage 方法从 CGImageRef 创建一个 NSImage:
Have you tried using the UIGetScreenImage() function?
It's private, but Apple allows to use it, so your app will be validated for the App Store, even if you use it.
You just need to declare its prototype, so the compiler won't complain:
Note: you can create a NSImage from the CGImageRef with the following NSImage method: