I am new to Core Image and am trying out some of the filters. I can get some of the filters to work but others just refused to work.
For example, I can get the CIGaussianGradient filter to work using codes like this:
CIVector *centerVector = [CIVector vectorWithX:150 Y:150];
CIColor *color0 = [CIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0];
CIColor *color1 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
NSNumber *radius = [NSNumber numberWithFloat:300.0];
CIImage *theCIImage = [CIFilter filterWithName:@"CIGaussianGradient" keysAndValues:@"inputCenter", centerVector, @"inputColor0", color0, @"inputColor1", color1, @"inputRadius", radius, nil].outputImage;
UIImage *newImage = [UIImage imageWithCIImage: theCIImage];
self.ImgView.image = newImage;
But I cannot get the CILinearGradient to work using simiar code such as this:
CIVector *point0 =[CIVector vectorWithX:0 Y:0];
CIVector *point1 =[CIVector vectorWithX:200 Y:200];
CIColor *color0 = [CIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0];
CIColor *color1 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
CIImage *theCIImage = [CIFilter filterWithName:@"CILinearGradient" keysAndValues:@"inputPoint0", point0, @"inputPoint1", point1, @"inputColor0", color0, @"inputColor1", color1, nil].outputImage;
UIImage *newImage = [UIImage imageWithCIImage: theCIImage];
self.ImgView.image = newImage;
What am I missing?
I am testing it on iOS 6.0.
This one worked for me on iOS 7.
CIContext *coreImageContext = [CIContext contextWithOptions:nil];
CIFilter *gradientFilter = [CIFilter filterWithName:@"CILinearGradient"];
[gradientFilter setDefaults];
CIColor *startColor = [CIColor colorWithCGColor:[UIColor yellowColor].CGColor];
CIColor *endColor = [CIColor colorWithCGColor:[UIColor redColor].CGColor];
CIVector *startVector = [CIVector vectorWithX:0 Y:0];
CIVector *endVector = [CIVector vectorWithX:100 Y:100];
[gradientFilter setValue:startVector forKey:@"inputPoint0"];
[gradientFilter setValue:endVector forKey:@"inputPoint1"];
[gradientFilter setValue:startColor forKey:@"inputColor0"];
[gradientFilter setValue:endColor forKey:@"inputColor1"];
CIImage *outputImage = [gradientFilter outputImage];
CGImageRef cgimg = [coreImageContext createCGImage:outputImage fromRect:CGRectMake(0, 0, 100, 100)];
UIImage *newImage = [UIImage imageWithCGImage:cgimg];
self.ImgView.image = newImage;
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