Muzamil Hassan
Muzamil Hassan

Reputation: 851

applying different filters

I want to ask that i am using core image and applying some filter is used this filter

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

but i wan to know that how i implement other filters i tried but app crashes so i want to apply like these filters which is built in i chech using log

    CISourceOutCompositing,
    CISourceOverCompositing,
    CIStraightenFilter,
    CIStripesGenerator,
    CITemperatureAndTint,
    CIToneCurve,
    CIVibrance,
    CIVignette,
    CIWhitePointAdjust

Now i want to apply these filters. Which methods i should use?

Upvotes: 1

Views: 4092

Answers (2)

akshay1188
akshay1188

Reputation: 1667

Just log this:

NSArray *properties = [CIFilter filterNamesInCategory:
                           kCICategoryBuiltIn];
    NSLog(@"%@", properties);
    for (NSString *filterName in properties) {
        CIFilter *fltr = [CIFilter filterWithName:filterName];
        NSLog(@"%@", [fltr attributes]);
    }

And you will get all the filter names and the attributes you need to assign to them. Once you have all the keys, it's easy.

e.g.log o/p -

 CIAttributeFilterDisplayName = Vibrance;
    CIAttributeFilterName = CIVibrance;
    inputAmount =     {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 0;
        CIAttributeIdentity = 0;
        CIAttributeMax = 1;
        CIAttributeMin = "-1";
        CIAttributeSliderMax = 1;
        CIAttributeSliderMin = "-1";
        CIAttributeType = CIAttributeTypeScalar;
    };
    inputImage =     {
        CIAttributeClass = CIImage;
        CIAttributeType = CIAttributeTypeImage;
    };

From this you can figure out that for the filter CIVibrance you have the key inputAmount. You can write it as:

CIFilter* filter = [CIFilter filterWithName:@"CIVibrance"
                                  keysAndValues:kCIInputImageKey,beginImage,@"inputAmount",[NSNumber numberWithFloat:0.8], nil];

Upvotes: 8

ultramiraculous
ultramiraculous

Reputation: 1102

Some, but not all of those filters aren't available on iOS. It took me a while to notice that, too.

If you look at:

https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html

The filters that work in iOS5 will say "Available in Mac OS X v10.4 and later and in iOS 5.0 and later.", but a lot of them just say "Available in Mac OS X v10.4". If you try and chain multiple CoreImage filters, and one of them isn't available, you'll get no result back from one of the filters. The CoreImage behavior when a filter isn't available is to return nil.

As a side note, GPUImage (https://github.com/BradLarson/GPUImage) may do what you're looking for. It can apply a filter to a UIImage or alter a live stream from the camera, and it's compatible with iOS4, if that matters.

Upvotes: 1

Related Questions