سؤال

I'm using a bunch of CIFilter filters in my app to adjust brightness, saturation etc' and they are working fine. I'm having some issues with inputSharpness. If I touch the sharpness slider the picture just disappears. Relevant code:

UIImage *aUIImage = [imageView image];
CGImageRef aCGImage = aUIImage.CGImage;
aCIImage = [CIImage imageWithCGImage:aCGImage];

//Create context
context = [CIContext contextWithOptions:nil];
sharpFilter = [CIFilter filterWithName:@"CIAttributeTypeScalar" keysAndValues: @"inputImage", aCIImage, nil];

....

- (IBAction)sharpSliderChanged:(id)sender
{

    //Set filter value
    [sharpFilter setValue:[NSNumber numberWithFloat:sharpSlider.value] forKey:@"inputSharpness"];

    //Convert CIImage to UIImage
    outputImage = [sharpFilter outputImage];
    CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
    newUIImage = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);

    //add image to imageView
    [imageView setImage:newUIImage];

}
هل كانت مفيدة؟

المحلول

I've read a post with a similar question, there a possible solution was to add a category for the UIImage effect you want to provide. The only difference here is that you should use one of the CIColorControls Parameters: inputSharpness and the CISharpenLuminance filter.

Back to your question: It seems from your comments you have some problem about how you initialize your filter. I take a look to the official documentation and I would use CISharpenLuminance instead during the initialization phase. It is only available in ios 6 though.

EDIT Like i said if you want to stick with core image the feature you want is available on iOS 6 only. I can recommend you to use a third party lib: GPU library from bradlarson if you want to be compatible with ios 5.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top