[英]iOS CIImage stretch the image
尽管我将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创建我的项目
尝试通过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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.