Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flatten UIViews Subviews to UIImage iPhone 3.0

I have a UIView that has several UIImageViews as subviews. Each of these subviews has had different affine transform applied. I would like to take what amounts to a screen capture of my UIView, capturing it as a UIImage, or some other image representation.

The method I have tried already, rendering the layers to a CGContext with:

[view.layer renderInContext:UIGraphicsGetCurrentContext()];

doesn't preserve the positioning or other affine transformations of my subviews.

I would really appreciate a kick in the right direction.

like image 385
SooDesuNe Avatar asked Sep 15 '09 00:09

SooDesuNe


1 Answers

Try this:

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
like image 93
Martin Gordon Avatar answered Sep 20 '22 02:09

Martin Gordon