Contents

perspectiveTransform()

Alters an image’s geometry to adjust the perspective.

Declaration

class func perspectiveTransform() -> any CIFilter & CIPerspectiveTransform

Return Value

The adjusted image.

Discussion

This method applies the perspective transform filter to an image. The effect alters the geometry of an image to simulate the observer changing viewing position. You can use the perspective filter to skew an image.

The perspective transform filter uses the following properties:

inputImage

An image with the type CIImage.

topLeft

A CGPoint in the input image mapped to the top-left corner of the output image.

topRight

A CGPoint in the input image mapped to the top-right corner of the output image.

bottomLeft

A CGPoint in the input image mapped to the bottom-left corner of the output image.

bottomRight

A CGPoint in the input image mapped to the bottom-right corner of the output image.

The following code creates a filter that changes the perspective of the input image:

func perspectiveTransform(inputImage: CIImage) -> CIImage {
    let perspectiveTransformFilter = CIFilter.perspectiveTransform()
    perspectiveTransformFilter.inputImage = inputImage
    perspectiveTransformFilter.topLeft = CGPoint(x: 100, y: 3984)
    perspectiveTransformFilter.topRight = CGPoint(x: 3732, y: 3025)
    perspectiveTransformFilter.bottomLeft = CGPoint(x: 0, y: 500)
    perspectiveTransformFilter.bottomRight = CGPoint(x: 4032, y: 120)
    return perspectiveTransformFilter.outputImage!
}

[Image]

See Also

Filters