首页 > 代码库 > ios 截屏(代码)
ios 截屏(代码)
//1.首先在storyboard中拖一些控件,包括UIButton控件,将UIButton控件拖线到控制器中(方法、CutImage)
//2.在CutImage方法中调用NSTimer方法
- (IBAction)CutImage:(UIButton *)sender {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 targer:self selector:@selector(clipImage) userInfo:nil repeats:NO];
}
//3.调用clipImage方法
-(void)clipImage
{
//1.创建图形上下为难
UIGraphicsBeginImageCOntextWithOptions(self.view.bounds.size,NO,0.0);
//2.调取方法截屏(截取的是全屏)
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
//3.获得当前的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//4.结束图形上下文
UIGraphicsEndImgeContext();
//5.打印数据
NSData *data =http://www.mamicode.com/UIImagePNGRepresentation(newImage);
[data writeToFile:@"/User/apple/DeskTop/new1.png" atomically:YES];
}
ios 截屏(代码)