Contents

stretchCrop()

Distorts an image by stretching or cropping to fit a specified size.

Declaration

class func stretchCrop() -> any CIFilter & CIStretchCrop

Return Value

The distorted image.

Discussion

This method applies the stretch crop filter to an image. This effect distorts an image by stretching an image and then applies the crop extent. If the crop value is 0, the filter only uses stretching. If the value is 1, then the filter only uses cropping.

The stretch crop filter uses the following properties:

inputImage

An image with the type CIImage.

centerStretchAmount

A float representing the amount of stretching of the center of the image as an NSNumber.

size

A CGPoint representing the desired size of the output image.

cropAmount

A float representing the amount of cropping you apply to achieve the target size as an NSNumber.

The following code creates a filter that results in a smaller image that’s distorted and cropped to be the defined size:

func stretchCrop(inputImage: CIImage) -> CIImage {
    let filter = CIFilter.stretchCrop()
    filter.inputImage = inputImage
    filter.cropAmount = 0.25
    filter.centerStretchAmount = 0.25
    filter.size = CGPoint(
        x: inputImage.extent.width * 2,
        y: inputImage.extent.size.height * 0.8
    )
    return filter.outputImage!
}

[Image]

See Also

Filters