gpt4 book ai didi

iOS CIImage 拉伸(stretch)图像

转载 作者:行者123 更新时间:2023-11-29 02:11:24 26 4
gpt4 key购买 nike

虽然我将我的 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;

2 个 ImageView (uiImageView 和 ciImageView)具有相同的“aspectFit”属性和相同的大小限制 (200x200)。但只有 (1) 正确显示图像,(2) 拉伸(stretch)图像。

有什么问题?谢谢。

我用 Xcode 6.2 创建我的项目

enter image description here

最佳答案

尝试通过 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();

关于iOS CIImage 拉伸(stretch)图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29248199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com