首页 > 其他 > 详细

十 、Quartz 2D 截屏

时间:2016-04-11 20:23:27      阅读:219      评论:0      收藏:0      [点我收藏+]

 

 

版本1,将图片保存到电脑桌面

- (IBAction)btnClick:(UIButton *)sender {
    
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    [self.view.layer renderInContext:ctx];
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    NSData *data = UIImagePNGRepresentation(img);
    
    [data writeToFile:@"/Users/你电脑的名字/Desktop/aa.png" atomically:YES];
    
}

 版本2,将图片保存到相册

- (IBAction)btnClick:(UIButton *)sender {
    
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 将屏幕绘制到上下文中
    [self.view.layer renderInContext:ctx];
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    // 将图片保存到相册
    UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    if (error) {
        NSLog(@"保存失败");
    }else{
        NSLog(@"保存成功");
    }
    
}

 

十 、Quartz 2D 截屏

原文:http://www.cnblogs.com/kinghx/p/5379688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!