2013-01-17 27 views
0

可能重複運行:
Why is glReadPixels() failing in this code in iOS 6.0?我想捕捉畫面時,任何比賽用OpenGL

我開發使用OpenGL遊戲,需要的屏幕截圖時,採取最好的拍攝和上傳臉譜,但當我採取屏幕拍攝其唯一的黑色屏幕。我做的事 ? 我也在鏈接中使用代碼: take screen Programmatically of UIview+glview 和類似的代碼 但沒有成功。

我起訴從代碼:http://developer.apple.com/library/ios/#qa/qa1704/_index.html

但是所有的代碼導致模擬器的圖像不在設備(在設備只有黑色或白色)

+0

上述鏈接問題(以及我的評論)的答案解釋了爲什麼基於glReadPixels()的代碼返回黑色圖像。您需要在顯示屏幕內容之前捕獲屏幕內容或使用保留的支持。 –

+0

我使用的是OpenGLES2DView的子類。在這個類中,我想截取屏幕截圖,當使用glReadPixels時,它在設備中不起作用,但在simnulator中正確。 –

+0

再次,在那裏閱讀答案。捕捉失敗的原因是,在iOS 6.0+中將內容渲染到屏幕後,glReadPixels()無法使用。您需要保留爲CAEAGLLayer啓用的備份,或者在調用「-presentRenderbuffer:」之前使用glReadPixels()。 –

回答

0

如果你想利用截屏,然後又嘗試用代碼&檢查:

CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
+0

此代碼僅生成白色圖像,而不是我項目中的任何圖形。 –

0

試試這個,這將採取查看截圖並保存到設備的相冊。

-(IBAction)captureScreen:(id)sender 
{ 
    UIGraphicsBeginImageContext(self.view.bounds.size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage *snapImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    UIImageWriteToSavedPhotosAlbum(snapImage, nil, nil, nil); 
}