clip(to:mask:)
Maps a mask into the specified rectangle and intersects it with the current clipping area of the graphics context.
Declaration
func clip(to rect: CGRect, mask: CGImage)Parameters
- rect:
The rectangle to map the
maskparameter to. - mask:
An image or an image mask. If
maskis an image, then it must be in the DeviceGray color space, may not have an alpha component, and may not be masked by an image mask or masking color.
Discussion
If the mask parameter is an image mask, then Core Graphics clips in a manner identical to the behavior seen with the CGContextDrawImage function —the mask indicates an area to be left unchanged when drawing. The source samples of the image mask determine which points of the clipping area are changed, acting as an “inverse alpha” value. If the value of a source sample in the image mask is S, then the corresponding point in the current clipping area is multiplied by an alpha value of (1–S). For example, if S is 1 then the point in the clipping area becomes transparent. If S is 0, the point in the clipping area is unchanged.
If the mask parameter is an image, then mask acts like an alpha mask and is blended with the current clipping area. The source samples of mask determine which points of the clipping area are changed. If the value of the source sample in mask is S, then the corresponding point in the current clipping area is multiplied by an alpha of S. For example, if S is 0, then the point in the clipping area becomes transparent. If S is 1, the point in the clipping area is unchanged.