gpt4 book ai didi

ios - 带有相机 View 的程序化屏幕截图

转载 作者:行者123 更新时间:2023-11-28 23:21:36 24 4
gpt4 key购买 nike

我正在使用下面的代码截取屏幕截图,但它将相机 View 替换为全黑(尽管所有其他 UI 元素都很好——我需要相机 View 和 UI 元素)。

我发现的所有类似问题的答案都非常陈旧/已弃用,或者在 Swift 中。如果有人对此问题有简单的 Obj-C 解决方案,我们将不胜感激。

谢谢!

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(self.view.window.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.view.window.bounds.size);
}

[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
if (imageData) {
[imageData writeToFile:@"Screenshot.png" atomically:YES];
NSLog(@"Screenshot write successful");
} else {
NSLog(@"Error while taking screenshot");
}

最佳答案

如果我理解正确,它可以帮助您获得视频屏幕 - https://stackoverflow.com/a/37789235/1678018
您可以将此图像添加到屏幕图像中(使用 UIGraphicsGetImageFromCurrentImageContext)。

在另一个 UIImage 之上添加 UIImage 的示例方法:Add UIImage on top of another UIImage

关于ios - 带有相机 View 的程序化屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59595381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com