Contents

spotLight()

Highlights a definined area of the image.

Declaration

class func spotLight() -> any CIFilter & CISpotLight

Return Value

The modified image.

Discussion

This method applies the spotlight filter to an image. The effect applies a directional spotlight effect to an image while creating a transparent area not highlighted by the spotlight.

The spotlight filter uses the following properties:

inputImage

An image with the type CIImage.

lightPointsAt

A CIVector with the x and y positions that the spotlight points at.

brightness

A float representing the brightness of the spotlight as an NSNumber.

lightPosition

A CIVector containing the x and y position of the spotlight.

concentration

A float representing the size of the spotlight in pixels as an NSNumber.

color

A CIColor representing the spotlight color.

The following code creates a filter that results in only the bottom left of the image becoming visible while the rest of the image gradually becomes transparent:

func spotlight(inputImage: CIImage) -> CIImage {
    let spotlightFilter = CIFilter.spotLight()
    spotlightFilter.inputImage = inputImage
    spotlightFilter.lightPointsAt = CIVector(x: 100, y: 100)
    spotlightFilter.brightness = 10
    spotlightFilter.lightPosition = CIVector(x: 100, y: 100)
    spotlightFilter.concentration = 20
    return spotlightFilter.outputImage!
}

[Image]

See Also

Filters