How to correctly apply the Core Image filter

I have problems with the kernel image. what i am doing is getting the image from the UIImageView and then using some code that i found in the tutorials (i'm new to the main image) but then I want to return the sepia image to the same UIImageView when I ever try to put a new image in the view, which it just disappears, I tested it to see if the image contains an image, but it is not visible. any suggestions on what to do?

EDIT: OK, I got a sepia filter to work, so I tried posterization, and I had the same problem as the image just disappears. Here is the code:

CIImage *beginImage = [CIImage imageWithCGImage:[image_view.image CGImage]];
context = [CIContext contextWithOptions:nil];
filter = [CIFilter filterWithName:@"CIColorPosterize" keysAndValues:kCIInputImageKey, beginImage,@"inputLevels",[NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
[image_view setImage:newImg];
CGImageRelease(cgimg);
+5
source share
2 answers

- (, UIImageView * myImageView)

CIImage *beginImage = [CIImage imageWithCGImage:[myImageView.image CGImage]];
CIContext *context = [CIContext contextWithOptions:nil];

CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" keysAndValues: kCIInputImageKey, beginImage, @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];

CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];

[myImageView setImage:newImg];

CGImageRelease(cgimg);
+11

Swift 3.0 Xcode 8.2 (My imageView "@IBOutlet var photoImageView: UIImageView!" ) iPhone 7Plus iOS 10

    guard let myImageView = self.photoImageView.image else
    {
        return
    }
    guard let cg = myImageView.cgImage else
    {
        return
    }
    let beginImage = CIImage(cgImage: cg)
    let context : CIContext = CIContext(options: nil)
    let inputParams : [String : Any]? = [kCIInputImageKey : beginImage,
                                        "inputIntensity" : NSNumber(value : 0.8)]
    let filter : CIFilter = CIFilter(name: "CISepiaTone", withInputParameters: inputParams)!
    let outputImage : CIImage? = filter.outputImage!

    if let outputImage = outputImage
    {
        let cgImage : CGImage? = context.createCGImage(outputImage, from: outputImage.extent)!

        if let cg = cgImage
        {
            let newImage : UIImage = UIImage(cgImage: cg)
            photoImageView.image = newImage
        }
    }
0

All Articles