Created
March 30, 2016 02:43
-
-
Save fhefh2015/9d6486f703b65e71f2502a50fd69a1ef 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
// | |
// ViewController.m | |
// 图片截屏 | |
// | |
#import "ViewController.h" | |
@interface ViewController () | |
@property (weak, nonatomic) IBOutlet UIImageView *picView; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
[self getScreenShot]; | |
} | |
- (void)getScreenShot { | |
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0); | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
[self.view.layer renderInContext:ctx]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
//保存到相册 | |
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); | |
} | |
#pragma mark - 只能使用该方法 | |
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void*)contextInfo { | |
NSLog(@"save ok"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment