perspectiveTransform()
Alters an image’s geometry to adjust the perspective.
Declaration
class func perspectiveTransform() -> any CIFilter & CIPerspectiveTransformReturn 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:
inputImageAn image with the type CIImage.
topLeftA CGPoint in the input image mapped to the top-left corner of the output image.
topRightA CGPoint in the input image mapped to the top-right corner of the output image.
bottomLeftA CGPoint in the input image mapped to the bottom-left corner of the output image.
bottomRightA 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]