0

Possible Duplicate:
Why is glReadPixels() failing in this code in iOS 6.0?

I am developing a game with OpenGL, need a screen shot when best shot taken and upload facebook but when i take screen shot its only black screen. what i do ? I also use code in link : take screen Programmatically of UIview+glview and similar code but no success.

i am suing code from : http://developer.apple.com/library/ios/#qa/qa1704/_index.html

But All code result an image in simulator not in device(in device only black or white)

Community
  • 1
  • 1
  • The answer to the above-linked question (and my comment there) explains why your glReadPixels()-based code is returning a black image. You need to either capture the screen contents before they are presented or use retained backing. – Brad Larson Jan 17 '13 at 17:29
  • i am using class which is subclass of OpenGLES2DView.In this class i want to take a screenshot, when use glReadPixels it's not worked in device but in simnulator go right. – Shiv Kumar Singh Jan 23 '13 at 11:03
  • Again, read the answer there. The reason your capture is failing is that glReadPixels() cannot be used after your content has been rendered to the screen in iOS 6.0+. You need to either have retained backing turned on for your CAEAGLLayer, or use glReadPixels() before `-presentRenderbuffer:` is called. – Brad Larson Jan 23 '13 at 15:20
  • yes, I forget that point but now my issue is solved. when device capture image go some slow means stop few miliseconds. – Shiv Kumar Singh Jan 24 '13 at 09:19

2 Answers2

0

If you want to take screen shot then also try with that code & check:

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
Vishal
  • 8,246
  • 6
  • 37
  • 52
0

Try this this will take screenshot of view and save into device photo album.

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