美文网首页iOS开发札记
IOS获取设备屏幕代码(截屏)

IOS获取设备屏幕代码(截屏)

作者: 向天再借五公分 | 来源:发表于2016-07-18 09:38 被阅读3030次
-(void) screenShot{
    
  UIGraphicsBeginImageContext(self.bounds.size);   //self为需要截屏的UI控件 即通过改变此参数可以截取特定的UI控件 
  [self.layer renderInContext:UIGraphicsGetCurrentContext()];    
  UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();    
  NSLog(@"image:%@",image); //至此已拿到image

  UIImageView *imaView = [[UIImageView alloc] initWithImage:image];   
  imaView.frame = CGRectMake(0, 700, 500, 500);    
  [self addSubview:imaView];    
    
  UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);//把图片保存在本地
}

相关文章

网友评论

    本文标题:IOS获取设备屏幕代码(截屏)

    本文链接:https://www.haomeiwen.com/subject/xmypjttx.html