我一直在閱讀已解決的問題,如何以編程方式截圖,但我似乎無法得到我讀過的工作在精靈套件。例如:如何以編程方式在Sprite-Kit中截取屏幕截圖?
這個問題3210
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"foo.png" atomically:YES];
UPDATE 2011年4月:視網膜顯示,第一行變成這樣:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);
給了我這個信息,這是我在我的遊戲測試但它不起作用,因爲SKScene上沒有識別窗口。我試圖用場景替換它,但沒有奏效。有什麼建議麼?
我也試過這樣:
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
這是我在這個問題中發現:ios Sprite Kit screengrab?
但它似乎沒有工作或者是因爲它不承認的規模,或者邊界在第二線。
還不如在空白圖像或只有部分工作的最佳解決方案?執行屏幕截圖時,屏幕上有什麼內容? – sangony
它是菜單上的遊戲,它顯示用戶的高分,並且我想在用戶點擊Twitter或Facebook按鈕時執行它,然後將其附加到共享帖子。因此,如果可能的話,我希望它可以保存到應用程序中,以便可以在「share.png」的社交分享中引用它,如果這樣做合理的話。 @sangony – user3576196
它沒有工作的方式是因爲它不承認第一行中的縮放比例,並且在第二行中沒有修改self.bounds @sangony – user3576196