The basic principle is to depict the uiview layer mainly in the graphics context. UIView Global photo and local photo code is as follows:
1 UIView Global photo shoot
- (UIImage *) screenImage:(UIView *)view {
UIImage *screenImage;
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenImage;
}
2 UIView Local photo
- (UIImage *) screenImage:(UIView *)view rect:(CGRect)rect {
CGPoint pt = rect.origin;
UIImage *screenImage;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextConcatCTM(context,
CGAffineTransformMakeTranslation(-(int)pt.x, -(int)pt.y));
[view.layer renderInContext:context];
screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenImage;
}
Source: http://blog.csdn.net/lbj05/archive/2011/04/02/6297209.aspx