Contents

maskToAlpha()

Converts an image to a white image with an alpha component.

Declaration

class func maskToAlpha() -> any CIFilter & CIMaskToAlpha

Return Value

The modified image.

Discussion

This method applies the mask-to-alpha filter to an image. The value of the alpha component is determined by the grayscale value of the input image. Black pixels become completely transparent, white pixels are completely solid.

The mask-to-alpha filter uses the following properties:

inputImage

An image with the type CIImage.

The following code creates a filter that makes the input image’s background transparent:

func maskToAlpha(inputImage: CIImage) -> CIImage {
    let maskToAlphaFilter = CIFilter.maskToAlpha()
    maskToAlphaFilter.inputImage = inputImage
    return maskToAlphaFilter.outputImage!
}

[Image]

See Also

Color Effect Filters