Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Created March 30, 2016 02:43
Show Gist options
  • Save fhefh2015/9d6486f703b65e71f2502a50fd69a1ef to your computer and use it in GitHub Desktop.
Save fhefh2015/9d6486f703b65e71f2502a50fd69a1ef to your computer and use it in GitHub Desktop.
屏幕截图
//
// 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