b2cloud

15th July 2013

Using CoreImage filters

Guides | Tutorial By 4 years ago

CoreImage has some pretty neat APIs. A lot of them aren’t very well known. I’m going to show off how easy it is to use the image filters, which can be used to add effects to an image.

I’ll demonstrate the dot filter, but there are many others which I have listed at the bottom.

First you need to import and link with the CoreImage.framework

#import 

Now the class for adding the effects is CIFilter. Open your image and make a CIImage version of it (specifically for CoreImage use). Then make a CIFilter of “CIDotScreen”, this is the type of filter that will be created.

UIImage* inputImage = [UIImage imageNamed:@"image.jpg"];
CIImage* filterInputImage = [CIImage imageWithCGImage:inputImage.CGImage];

CIFilter* filter = [CIFilter filterWithName:@"CIDotScreen"];

Now input the image and get the output image (which is processed with the filter).

[filter setValue:filterInputImage forKey:kCIInputImageKey];

CIImage* filterOutputImage = filter.outputImage;

To make it back into a UIImage, a CIContext needs to be used, as so

CIContext* ctx = [CIContext contextWithOptions:nil];
CGImageRef createdImage = [ctx createCGImage:filterOutputImage fromRect:filterOutputImage.extent];

UIImage* outputImage = [UIImage imageWithCGImage:createdImage];

CGImageRelease(createdImage);
createdImage = nil;

And that’s it. Here’s a list of all the filters, that can be used in place of “CIDotScreen”.

NSLog(@"%@", [CIFilter filterNamesInCategory:kCICategoryBuiltIn]);

(
	CIAdditionCompositing,
	CIAffineClamp,
	CIAffineTile,
	CIAffineTransform,
	CIBarsSwipeTransition,
	CIBlendWithMask,
	CIBloom,
	CIBumpDistortion,
	CIBumpDistortionLinear,
	CICheckerboardGenerator,
	CICircleSplashDistortion,
	CICircularScreen,
	CIColorBlendMode,
	CIColorBurnBlendMode,
	CIColorControls,
	CIColorCube,
	CIColorDodgeBlendMode,
	CIColorInvert,
	CIColorMap,
	CIColorMatrix,
	CIColorMonochrome,
	CIColorPosterize,
	CIConstantColorGenerator,
	CICopyMachineTransition,
	CICrop,
	CIDarkenBlendMode,
	CIDifferenceBlendMode,
	CIDisintegrateWithMaskTransition,
	CIDissolveTransition,
	CIDotScreen,
	CIEightfoldReflectedTile,
	CIExclusionBlendMode,
	CIExposureAdjust,
	CIFalseColor,
	CIFlashTransition,
	CIFourfoldReflectedTile,
	CIFourfoldRotatedTile,
	CIFourfoldTranslatedTile,
	CIGammaAdjust,
	CIGaussianBlur,
	CIGaussianGradient,
	CIGlideReflectedTile,
	CIGloom,
	CIHardLightBlendMode,
	CIHatchedScreen,
	CIHighlightShadowAdjust,
	CIHoleDistortion,
	CIHueAdjust,
	CIHueBlendMode,
	CILanczosScaleTransform,
	CILightenBlendMode,
	CILightTunnel,
	CILinearGradient,
	CILineScreen,
	CILuminosityBlendMode,
	CIMaskToAlpha,
	CIMaximumComponent,
	CIMaximumCompositing,
	CIMinimumComponent,
	CIMinimumCompositing,
	CIModTransition,
	CIMultiplyBlendMode,
	CIMultiplyCompositing,
	CIOverlayBlendMode,
	CIPinchDistortion,
	CIPixellate,
	CIRadialGradient,
	CIRandomGenerator,
	CISaturationBlendMode,
	CIScreenBlendMode,
	CISepiaTone,
	CISharpenLuminance,
	CISixfoldReflectedTile,
	CISixfoldRotatedTile,
	CISmoothLinearGradient,
	CISoftLightBlendMode,
	CISourceAtopCompositing,
	CISourceInCompositing,
	CISourceOutCompositing,
	CISourceOverCompositing,
	CIStarShineGenerator,
	CIStraightenFilter,
	CIStripesGenerator,
	CISwipeTransition,
	CITemperatureAndTint,
	CIToneCurve,
	CITriangleKaleidoscope,
	CITwelvefoldReflectedTile,
	CITwirlDistortion,
	CIUnsharpMask,
	CIVibrance,
	CIVignette,
	CIVortexDistortion,
	CIWhitePointAdjust
)
  • blackjack75

    You forgot to escape the CoreImage/CoreImage above and it is treated as a HTML tag so it becomes invisible.

Recommended Posts

7 Tips From Apple's iOS Human Interface Guidelines

Post by 4 years ago

With Appleā€™s iOS Human Interface Guidelines now available on the iBook Store, here some important tips to keep in mind when designing an app.

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!