Created
August 28, 2013 16:01
-
-
Save zhangwc/6367735 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//把view截图为UIImage | |
- (UIImage *)renderInImage:(UIView *)view | |
{ | |
UIGraphicsBeginImageContext(view.bounds.size); | |
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return (img); | |
} | |
//currentView截图转换为PDF | |
- (NSMutableData *)renderInView:(UIView *)currentView | |
{ | |
NSMutableData *mtlData = [[[NSMutableData alloc] init] autorelease]; | |
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)mtlData); | |
CGRect mediaBox = currentView.bounds; | |
CGContextRef ctx = CGPDFContextCreate(dataConsumer, &mediaBox, NULL); | |
CGPDFContextBeginPage(ctx, NULL); | |
CGContextScaleCTM(ctx, 1, -1); | |
CGContextTranslateCTM(ctx, 0, -mediaBox.size.height); | |
[currentView.layer renderInContext:ctx]; | |
CGPDFContextEndPage(ctx); | |
CFRelease(ctx); | |
CGDataConsumerRelease(dataConsumer); | |
return (mtlData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment