我正在使用CIFilter将过滤器添加到图像。过滤图像后得到的图像具有以下大小:CGRectMake(10, 10, 70, 70)
。我无法将结果图像内容模式设置为ScaleAspectFill
。这是代码:
filter2image.frame = CGRectMake(90, 10, 70, 70)
let filter2data = CIFilter(name: "CIPhotoEffectChrome")
filter2data.setValue(CIImage(image: imageView.image), forKey: kCIInputImageKey)
self.filter2image.image = UIImage(CIImage: filter2data.outputImage)
filter2image.contentMode = UIViewContentMode.ScaleAspectFill
最佳答案
设置contentMode后,尝试更改框架。像这样:
let filter2data = CIFilter(name: "CIPhotoEffectChrome")
filter2data.setValue(CIImage(image: imageView.image), forKey: kCIInputImageKey)
self.filter2image.image = UIImage(CIImage: filter2data.outputImage)
filter2image.contentMode = UIViewContentMode.ScaleAspectFill
filter2image.frame = CGRectMake(90, 10, 70, 70)