首页 > 学院 > 开发设计 > 正文

ios截屏(代码)

2019-11-14 20:00:41
字体:
来源:转载
供稿:网友

//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 =UIImagePNGRePResentation(newImage);

  [data writeToFile:@"/User/apple/DeskTop/new1.png" atomically:YES];

  

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表