I need to use apple's auto enhance images in my code. I'v found example that apple showed but I'm unable to make it work. I'm not actually sure what am I doing wrong.
Here is what apple recommended: AutoEnhanceCode
Here is what I'm doing (imageFinal is UIImage that I want to enhance):
- (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;
}
}
Error that I get is: Incompatible pointer types sending 'const CFStringRef' (aka 'const struct __CFString *const') to parameter of type 'NSString *'
I really don't know how to use this kCGImagePropertyOrrientation. I just want to apply that simple enhance.
Cheers.
Here's a Swift version for Auto Enhancing a UIImage
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
}
}
Usage:
let autoEnhanced = image.autoEnhance() // returns optional UIImage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With