-
Notifications
You must be signed in to change notification settings - Fork 0
/
CaptureView.m
31 lines (27 loc) · 971 Bytes
/
CaptureView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// Copyright (c) 2012 Norman Basham
// http://www.apache.org/licenses/LICENSE-2.0
//
#import "CaptureView.h"
#import <QuartzCore/QuartzCore.h>
@implementation CaptureView
// NB: this implementation uses the CPU not GPU
+(UIImage*)viewToImage:(UIView*)v {
CGFloat deviceMainScreenScale = 0.0;
BOOL optimizationExcludeAlpha = NO;
UIGraphicsBeginImageContextWithOptions(v.bounds.size, optimizationExcludeAlpha, deviceMainScreenScale);
[v.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+(NSData*)viewToPdf:(UIView*)v {
NSMutableData* pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, v.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[v.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
return pdfData;
}
@end