Contents

displacementDistortion()

Applies the grayscale values of the second image to the first image.

Declaration

class func displacementDistortion() -> any CIFilter & CIDisplacementDistortion

Return Value

The distorted image.

Discussion

This method applies the displacement distortion filter to an image. This effect distorts an image by applying the grayscale color values of the texture image.

The displacement distortion filter uses the following properties:

inputImage

An image with the type CIImage.

displacementImage

An image with the type CIImage.

scale

A float representing the scaling the filter uses to apply the texture to the input image as an NSNumber.

The following code creates a filter that applies the grayscale values of the displacement image to the input image:

func displacementDistortion(inputImage: CIImage) -> CIImage {
    // Create an interesting grayscale pattern.
    let displacementImage = CIFilter.checkerboardGenerator()
    displacementImage.color0 = CIColor.white
    displacementImage.color1 = CIColor.black
    displacementImage.width = 200
    let gaussianBlur = CIFilter.gaussianBlur()
    gaussianBlur.radius = 40
    gaussianBlur.inputImage = displacementImage.outputImage
    // Use it in the displacement filter.
    let filter = CIFilter.displacementDistortion()
    filter.displacementImage = gaussianBlur.outputImage
    filter.inputImage = inputImage
    filter.scale = 1000
    return filter.outputImage!
}

[Image]

See Also

Filters