虽然我将imageView设置为aspectFit,但通过CIImage创建的图像似乎总是被缩放以填充。
通过以下两种方式加载图像的简单示例:
// 1. load directly via UIImage
UIImage *imageByUIImage = [UIImage imageNamed:@"Megan-Fox-Look.jpg"];
self.uiImageView.image = imageByUIImage;
// 2. load via CIImage
NSString *filePath =
[[NSBundle mainBundle] pathForResource:@"Megan-Fox-Look" ofType:@"jpg"];
CIImage *ciImage =
[CIImage imageWithContentsOfURL:[NSURL fileURLWithPath:filePath]];
UIImage *imageByCIImage = [UIImage imageWithCIImage:ciImage scale:1.f orientation:UIImageOrientationUp];
self.ciImageView.image = imageByCIImage;两个图像视图(uiImageView和ciImageView)具有相同的“aspectFit”属性和相同的大小约束(200x200)。但只有(1)正确显示图像,(2)拉伸图像。
有什么问题吗?谢谢。
我用Xcode 6.2创建了我的项目

发布于 2015-03-25 07:43:34
尝试通过CIImage:加载
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"abcd" ofType:@"png"];
CIImage *ciImage = [CIImage imageWithContentsOfURL:[NSURL fileURLWithPath:filePath]];
UIImage *imageByCIImage = [UIImage imageWithCIImage:ciImage scale:1.0f orientation:UIImageOrientationUp];
UIGraphicsBeginImageContext(imageByCIImage.size);
[imageByCIImage drawInRect:CGRectMake(0,0,imageByCIImage.size.width,imageByCIImage.size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
self.imageview.image = newImage;
UIGraphicsEndImageContext();发布于 2019-03-20 21:46:17
CIImage文档声明:
尽管CIImage对象具有与其关联的图像数据,但它不是图像。
拉伸问题可能与UIImageView将管理实际呈现的事实有关。在其他帖子中,它可能会使用视图rect作为区域,而不是原始图像大小,使用CIFilters绘制或呈现CIContext。
上一篇文章解决了这个问题,Mattt的这篇文章也提到了其他帖子中的一个选项:使用CGImageRef中间表示。
UIImage(cgImage: self.context.createCGImage(outputImage, from: outputImage.extent)!)https://stackoverflow.com/questions/29248199
复制相似问题