iPhone - is it IMPOSSIBLE to grab the contents of a CALayers composition?

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-02-18T15:53:15Z Indexed on 2010/06/05 7:22 UTC
Read the original article Hit count: 493

Filed under:
|
|

I have a CALayer transformed in 3D on a offscreen UIView (much larger than 320x480).

How do I dump what is seen on this UIView to a UIImage?

NOTE: I Have edited the question to include this code...

This is how I create the layer...

CGRect area = CGRectMake (0,0,400,600];
vista3D = [[UIView alloc] initWithFrame:area ];

[self.view addSubview:vista3D];
[vista3D release];

transformed = [CALayer layer];
transformed.frame = area;
[vista3D.layer addSublayer:transformed];

CALayer *imageLayer = [CALayer layer];
imageLayer.doubleSided = YES; 

imageLayer.frame = area;
imageLayer.transform = CATransform3DMakeRotation(40 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);

imageLayer.contents = (id)myRawImage.CGImage;

[transformed addSublayer:imageLayer];

// Add a perspective effect
CATransform3D initialTransform = transformed.sublayerTransform;
initialTransform.m34 = 1.0 / -500;
transformed.sublayerTransform = initialTransform;

// now the layer is in perspective
// my next step is to "flatten" the composition into a UIImage

UIImage *thisIsTheResult = some magic command

thanks for any help!

EDIT 1: I have tried jessecurry solution but it gives me a flat layer without any perspective.

EDIT 2: I discovered a partial solution for this that works, but this solution gives me an image the size of the screen and I was looking for obtaining a higher resolution version, rendering off screen.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk