Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

screenshot programmatically does not work

I am doing this: but I always get a white picture. Does anybody knows why?

- (void) screenshotButtonAction{
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}

self is a uiviewcontroller and it holds a opengl view (UIView + CAEAGLLayer)

EDIT: I have realized that only the gl view is not screenshot-ed. Is strange, subviews and sublayers of the gl view shows fine but the opengl view is white in the taken picture. Does this have to be something with the current context?
This is an AR application and the gl view shows camera input + AR objects so, glview is always being rendered (refreshed) What could be happening here?

like image 615
nacho4d Avatar asked Jan 31 '26 19:01

nacho4d


1 Answers

Code looks good. Make sure you already added QuartzCore.framework and import it in your .m file.

#import <QuartzCore/QuartzCore.h>
like image 106
GeneCode Avatar answered Feb 02 '26 08:02

GeneCode