jov*_*vic 2 image-processing core-image uiimage ios
我需要在我的代码中使用苹果的自动增强图像。我找到了苹果展示的示例,但我无法使其工作。我实际上不确定我做错了什么。
这是苹果推荐的:AutoEnhanceCode
这是我正在做的事情(imageFinal 是我想要增强的 UIImage):
- (IBAction)enhance:(id)sender {
CIImage *myImage;
CIImage *image = [imageFinal CIImage];
NSDictionary *options = [NSDictionary dictionaryWithObject:[[image properties]valueForKey:kCIImageProperties] forKey:CIDetectorImageOrientation];
NSArray *adjustments = [myImage autoAdjustmentFiltersWithOptions:options];
for (CIFilter *filter in adjustments){
[filter setValue:myImage forKey:kCIInputImageKey];
myImage = filter.outputImage;
}
Run Code Online (Sandbox Code Playgroud)
}
我得到的错误是:不兼容的指针类型将“const CFStringRef”(又名“const struct __CFString *const”)发送到“NSString *”类型的参数
我真的不知道如何使用这个kCGImagePropertyOrientation。我只想应用这个简单的增强。
干杯。
这是自动增强 UIImage 的 Swift 版本
extension UIImage {
func autoEnhance() -> UIImage? {
if var ciImage = CIImage.init(image: self) {
let adjustments = ciImage.autoAdjustmentFilters()
for filter in adjustments {
filter.setValue(ciImage, forKey: kCIInputImageKey)
if let outputImage = filter.outputImage {
ciImage = outputImage
}
}
let context = CIContext.init(options: nil)
if let cgImage = context.createCGImage(ciImage, from: ciImage.extent) {
let finalImage = UIImage.init(cgImage: cgImage, scale: self.scale, orientation: self.imageOrientation)
return finalImage
}
}
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
let autoEnhanced = image.autoEnhance() // returns optional UIImage
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3197 次 |
最近记录: |