2

In my iPhone app, I am capturing the screen shot of the device. In the screen shot view I have different views with layer hierarchy as, at the bottom a blank background view, then over the background a image view, and over the image view a EAGLView. I want to capture the screen shot of the device with the frame size of the EAGLView and it should include the imageview and background view. Here is my code:

- (IBAction)captureScreen:(id)sender{

    UIGraphicsBeginImageContext(self.view.bounds.size);

    [self.cameraAppView.layer renderInContext:UIGraphicsGetCurrentContext()]; // cameraAppView is the EAGLView

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], cameraAppView.frame);

    UIImage *img = [UIImage imageWithCGImage:imageRef];

    CGImageRelease(imageRef);
}

But now I am only getting the screen shot of EAGLView, I want to get screen shot of the device through the EAGLView frame size. How can I do that?

Edit

Sorry, I missed a point in my question. There are also some other subviews in the same screen. But all of them are top of the EAGLView. I want to capture the image of the views, below the EAGLView including the EAGLView content.

Mithuzz
  • 1,091
  • 14
  • 43

2 Answers2

1

At last found a answer myself. Its a tricky one and I am not sure is there any other proper way to do this. For my need it is working perfectly. What I did is, just hide the subviews, which should not be included in the screen shot image, and unhide the subviews once the image is captured.

Please do share if someone find any one find a proper way to do this.

Mithuzz
  • 1,091
  • 14
  • 43
0

Specify the view you want to capture instead of

[self.cameraAppView.layer renderInContext:UIGraphicsGetCurrentContext()];

use

[self.cameraAppView.superView.superView.layer renderInContext:UIGraphicsGetCurrentContext()];

This will work if your EAGLView is a subView of your imageView which is a subView of the view you want to capture

Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • EAGLView is a subview of the view, and also ImageView is a subview of view. But its layer arrangement is like EAGLView is at the top, inage view at the middle and at the bottom View. – Mithuzz Jun 26 '12 at 11:16
  • and if i change the code like you said, it is equal to self.view.layer right? But in this case I am getting all the subviews from that view. I am sorry, i missed a point in my question, please check updated one. – Mithuzz Jun 26 '12 at 11:21