سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top