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();
网友评论