Andy
Andy

Reputation: 4746

iPhone: how to take screen shots programmatically when using 3d layer transformations

I am trying to programmatically save an image of the current view to a UIImage. the current view contains a background, and a number of UIImageViews that have had a 3d transformation applied to the layer, e.g.

CATransform3D t = CATransform3DIdentity;
t = CATransform3DRotate(t, rotationX, 1.0, 0, 0);
t = CATransform3DRotate(t, rotationY, 0, 1.0, 0);
object.layer.transform = t;

I am currently grabbing a screenshot of the current view with the following code:

UIGraphicsBeginImageContext(background.bounds.size);
[background.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

However, the 3d transformations on the objects are lost, e.g. the objects appear in the saved image as if no 3d transformations have been applied. Is there a way to grab a screen shot programmatically that will include the 3d transformations?

UIGetScreenImage() is not an option as that is a private API and this app is going to the app store.

Upvotes: 2

Views: 1037

Answers (1)

Julio Gorgé
Julio Gorgé

Reputation: 10106

I don't think it can be done at the moment, as renderInContext does not render Core Animation transforms and UIGetScreenImage() is not a public API as you well point out. The same question was asked already on StackOverflow:

1) How do I create/render a UIImage from a 3D transformed UIImageView?

2) CALayer renderInContext

If that feature is key to your application, I'd look into using an OpenGL view and capturing the color buffer (which can be rendered offscreen if you don't want to display it).

Upvotes: 1

Related Questions