截屏

作者: 梦想家家家 | 来源:发表于2017-09-16 10:03 被阅读8次
    NSLog(@"点击了");
    
    // 截屏
    // 开启上下文
    UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, NO, 1);

    // 获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 渲染图层
    [self.imageView.layer renderInContext:ctx];
    
    // 获取上下文中的图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    //将UIImage转换成CGImageRef
    CGImageRef sourceImageRef = [image CGImage];
    
    //按照给定的矩形区域进行剪裁
    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, self.imageView.imageRectInView);
    
    //将CGImageRef转换成UIImagenewImageRef
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
    
    // 关闭上下文
    UIGraphicsEndImageContext();

相关文章

网友评论

      本文标题:截屏

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