Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在精灵套件中抓取屏幕截图?_Ios_Objective C_Sprite Kit_Screenshot - Fatal编程技术网

Ios 如何在精灵套件中抓取屏幕截图?

Ios 如何在精灵套件中抓取屏幕截图?,ios,objective-c,sprite-kit,screenshot,Ios,Objective C,Sprite Kit,Screenshot,当我试图在spritekit中抓取屏幕截图时。我已经尝试了所有我能在网上找到的方法。他们没有工作 UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *gameOverScreenImage = UIGraphicsG

当我试图在spritekit中抓取屏幕截图时。我已经尝试了所有我能在网上找到的方法。他们没有工作

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *gameOverScreenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
只是不起作用

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

无法识别self.bounds和scale。

我不确定
-drawViewHierarchyInRect:AfterScreenUpdate:
是否应该与SKView一起使用(我假设是这样),但第二个示例未编译的原因是:(1)您试图调用它,并且
self
上的
bounds
(可能是UIViewController)而不是
self.view
和(2)您尚未定义
scale
的值。只需更改这两行:

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];

此外,除非视图是透明的,否则
UIGraphicsBeginImageContextWithOptions的第二个参数“不透明”不应为“否”,并且只有在某些可能不包括此参数的情况下,才需要将“AfterScreenUpdate”设置为“是”。通过更改这些选项,您可能会看到更好的性能。

因此,您的问题不是没有截图,而是无法识别
边界
缩放
?@JustSid您可以这么说。第二段据称在sprite kit中成功运行。但是当我尝试使用它时,它没有被识别。没有关于第一段代码的警告,它只是不起作用。我在我的一个游戏中使用了你的第二种方法,并且工作正常,你应该从“ViewController.h”调用该方法,而不是从“MyScene.h”
只是不起作用
请进一步解释。它起作用了!我试着把self改成self.view,但我没有改变第一个。谢谢你帮我解决这个问题,你的解释对我很有意义。很抱歉,我不能投票,因为我刚刚注册。一旦我获得15个声誉,我会投票支持的。没问题。您可以单击答案旁边的复选框,将其视为已解决问题。