Question

I have set up a camera and I managed to add the Cocos2d Layer above the camera, Now I want to take a screenshot of the total view i.e the camera and with the image on the layer above the camera.

Since my CCLayer is made transparent the camera can be seen through.

Any ideas/links/details on how to do this.. ?

Thanks in advance for your time :)

EDIT: THIS IS MY CODE FOR THE SCREENSHOT

UIGraphicsBeginImageContext([CCDirector sharedDirector].openGLView.superview.frame.size);
    [[CCDirector sharedDirector].openGLView.superview.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndPDFContext();

    CGRect rect;
    rect = CGRectMake(0, 0, 480, 320);
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage],[CCDirector sharedDirector].openGLView.superview.frame);
    UIImage * img =[UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
Was it helpful?

Solution

 UIGraphicsBeginImageContext(self.view.frame.size); 
 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
 UIImage *viewImage=UIGraphicsGetImageFromCurrentImageContext(); 
 UIGraphicsEndImageContext();

//It will give you the uiimage

OTHER TIPS

To all those who are looking for the same thing ..! I have got it working using AVFoundation framework. This is one nice tutorial on how to achieve this :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top