iOS截图

来源:互联网 发布:矩阵理论教材推荐 编辑:程序博客网 时间:2024/05/22 08:21

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

//    1.开始图形上下文

    CGSize imageSize = self.view.bounds.size;

    UIGraphicsBeginImageContextWithOptions(imageSize, NO0.0);

    

    //2.将某个view的所有内容渲染到图形上下文中

    CGContextRef  contextRef = UIGraphicsGetCurrentContext();

    [self.view.layer renderInContext:contextRef];

    //3.取的图片

    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();

    CGImageRef subImage = CGImageCreateWithImageInRect(image.CGImageCGRectMake(00self.view.bounds.size.width * 0.9self.view.bounds.size.height));

    UIImage * newImage = [UIImage imageWithCGImage:subImage];

    //写入本地文件

    [UIImagePNGRepresentation(newImage) writeToFile:@"/Users/Lenny/Desktop/view.png"  atomically:YES];

    //结束图形上下文

    UIGraphicsEndImageContext();

    

}


0 0
原创粉丝点击