iOS10以上
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
format.prefersExtendedRange = YES;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.imageView.size format:format];
__weak typeof(self) weakSelf = self;
UIImage *tmpImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
return [weakSelf.imageView.layer renderInContext:rendererContext.CGContext];
}];
iOS 10以下的方式
UIGraphicsBeginImageContextWithOptions(self.selectedImage.size, NO, self.selectedImage.scale);
[self.selectedImage drawAtPoint:CGPointZero];
CGFloat scale = self.selectedImage.size.width / self.imageView.width;
CGContextScaleCTM(UIGraphicsGetCurrentContext(), scale, scale);
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *tmpImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
可加群一起交流共同学习:801216530。
网友评论