A type that applies image processing operations to rendered content.
Create and configure a filter that produces an image processing effect,
like adding a drop shadow or a blur effect, by calling one of the
factory methods defined by the `Filter` structure. Call the
``addFilter(_:options:)`` method to add the filter to a
``GraphicsContext``. The filter only affects content that you draw
into the context after adding the filter.
Returns a filter that applies a brightness adjustment.
This filter is different than `brightness` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
You can obtain an effect like that filter using a ``grayscale(_:)``
color multiply. However, this filter does match the
<doc://com.apple.documentation/documentation/CoreImage/CIColorControls>
filter's brightness adjustment.
- Parameters:
- amount: An amount to add to the pixel's color components.
- Returns: A filter that applies a brightness adjustment.
Returns a filter that applies a saturation adjustment.
This filter is equivalent to the `saturate` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
- Parameters:
- amount: The amount of the saturation adjustment. A value
of zero to completely desaturates each pixel, while a value of
one makes no change. You can use values greater than one.
- Returns: A filter that applies a saturation adjustment.
Returns a filter that inverts the color of their results.
This filter is equivalent to the `invert` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
- Parameters:
- amount: The inversion amount. A value of one results in total
inversion, while a value of zero leaves the result unchanged.
Other values apply a linear multiplier effect.
- Returns: A filter that applies a color inversion.
Returns a filter that multiplies by a given color matrix.
This filter is equivalent to the `feColorMatrix` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
The filter creates the output color `[R', G', B', A']` at each pixel
from an input color `[R, G, B, A]` by multiplying the input color by
the square matrix formed by the first four columns of the
``ColorMatrix``, then adding the fifth column to the result:
R' = r1 ✕ R + r2 ✕ G + r3 ✕ B + r4 ✕ A + r5
G' = g1 ✕ R + g2 ✕ G + g3 ✕ B + g4 ✕ A + g5
B' = b1 ✕ R + b2 ✕ G + b3 ✕ B + b4 ✕ A + b5
A' = a1 ✕ R + a2 ✕ G + a3 ✕ B + a4 ✕ A + a5
- Parameters:
- matrix: A ``ColorMatrix`` instance used by the filter.
- isPremultiplied: Whether the matrix is intended to be applied
to color components that have been multiplied by their opacity
value.
- Returns: A filter that transforms color using the given matrix.
Returns a filter that multiplies by a given color matrix.
This filter is equivalent to the `feColorMatrix` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
The filter creates the output color `[R', G', B', A']` at each pixel
from an input color `[R, G, B, A]` by multiplying the input color by
the square matrix formed by the first four columns of the
``ColorMatrix``, then adding the fifth column to the result:
R' = r1 ✕ R + r2 ✕ G + r3 ✕ B + r4 ✕ A + r5
G' = g1 ✕ R + g2 ✕ G + g3 ✕ B + g4 ✕ A + g5
B' = b1 ✕ R + b2 ✕ G + b3 ✕ B + b4 ✕ A + b5
A' = a1 ✕ R + a2 ✕ G + a3 ✕ B + a4 ✕ A + a5
- Parameters:
- matrix: A ``ColorMatrix`` instance used by the filter.
- Returns: A filter that transforms color using the given matrix.
Returns a filter that applies `shader` to the color of each
source pixel.
For a shader function to act as a color filter it must have
a function signature matching:
[[ stitchable ]] half4 name(float2 position, half4 color, args...)
where `position` is the user-space coordinates of the pixel
applied to the shader and `color` its source color, as a
pre-multiplied color in the destination color space. `args...`
should be compatible with the uniform arguments bound to
`shader`. The function should return the modified color value.
- Parameters:
- shader: The shader to apply to `self` as a color filter.
- Returns: A filter that applies the shader as a color
filter.
Returns a filter that applies a hue rotation adjustment.
This filter is equivalent to the `hue-rotate` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
- Parameters:
- angle: The amount by which to rotate the hue value of each
pixel.
- Returns: A filter that applies a hue rotation adjustment.
Returns a filter that applies `shader` to the contents of
the source layer.
For a shader function to act as a layer effect it must
have a function signature matching:
[[ stitchable ]] half4 name(float2 position,
SwiftUI::Layer layer, args...)
where `position` is the user-space coordinates of the
destination pixel applied to the shader, and `layer` is a
rasterized subregion of the source layer. `args...` should
be compatible with the uniform arguments bound to `shader`.
The `SwiftUI::Layer` type is defined in the
`<SwiftUI/SwiftUI.h>` header file. It exports a single
`sample()` function that returns a linearly-filtered pixel
value from a position in the source content, as a
premultiplied RGBA pixel value:
namespace SwiftUI {
struct Layer {
half4 sample(float2 position) const;
};
};
The function should return the color mapping to the
destination pixel, typically by sampling one or more pixels
from `layer` at location(s) derived from `position` and
them applying some kind of transformation to produce a new
color.
- Parameters:
- shader: The shader to apply as a layer effect.
- maxSampleOffset: If the shader function samples from
the layer at locations not equal to the destination
position, this value must specify the maximum sampling
distance in each axis, for all source pixels.
- Returns: A filter applies the shader as a layer effect.
Returns a filter that multiplies the alpha component by
a given color.
- Parameters:
- color: The color that the filter uses for the multiplication
operation.
- Returns: A filter that multiplies the alpha component.
Returns a filter that multiplies each color component by
the matching component of a given color.
- Parameters:
- color: The color that the filter uses for the multiplication
operation.
- Returns: A filter that multiplies color components.
Returns a filter that replaces each pixel with alpha components
within a range by a constant color, or transparency otherwise.
- Parameters:
- min: The minimum alpha threshold. Pixels whose alpha
component is less than this value will render as
transparent. Results are undefined unless `min < max`.
- max: The maximum alpha threshold. Pixels whose alpha
component is greater than this value will render
as transparent. Results are undefined unless `min < max`.
- color: The color that is output for pixels with an alpha
component between the two threshold values.
- Returns: A filter that applies a threshold to alpha values.
Returns a filter that applies `shader` as a geometric
distortion effect on the location of each pixel.
For a shader function to act as a distortion effect it must
have a function signature matching:
[[ stitchable ]] float2 name(float2 position, args...)
where `position` is the user-space coordinates of the
destination pixel applied to the shader. `args...` should be
compatible with the uniform arguments bound to `shader`. The
function should return the user-space coordinates of the
corresponding source pixel.
- Parameters:
- shader: The shader to apply as a distortion effect.
- maxSampleOffset: The maximum distance in each axis
between the returned source pixel position and the
destination pixel position, for all source pixels.
- Returns: A new filter that applies the shader as a
distortion effect.
get · iOS 15.0+
luminanceToAlpha
TypeScript
static get luminanceToAlpha(): GraphicsContext_Filter
Swift declaration
static var luminanceToAlpha: GraphicsContext.Filter { get }
Returns a filter that sets the opacity of each pixel based on its
luminance.
The filter computes the luminance of each pixel
and uses it to define the opacity of the result, combined
with black (zero) color components.
- Returns: A filter that applies a luminance to alpha transformation.
Returns a filter that transforms the rasterized form
of subsequent graphics primitives.
- Parameters:
- matrix: A projection transform to apply to the rasterized
form of graphics primitives.
- Returns: A filter that applies a transform.
Returns a filter that applies a Gaussian blur.
- Parameters:
- radius: The standard deviation of the Gaussian blur.
- options: A set of options controlling the application of the
effect.
- Returns: A filter that applies Gaussian blur.
Returns a filter that adds a shadow.
SwiftUI produces the shadow by blurring the alpha channel of the
object receiving the shadow, multiplying the result by a color,
optionally translating the shadow by an amount,
and then blending the resulting shadow into a new layer below the
source primitive. You can customize some of these steps by adding
one or more shadow options.
- Parameters:
- color: A ``Color`` that tints the shadow.
- radius: A measure of how far the shadow extends from the edges
of the content receiving the shadow.
- x: An amount to translate the shadow horizontally.
- y: An amount to translate the shadow vertically.
- blendMode: The ``GraphicsContext/BlendMode-swift.struct`` to use
when blending the shadow into the background layer.
- options: A set of options that you can use to customize the
process of adding the shadow. Use one or more of the options
in ``GraphicsContext/ShadowOptions``.
- Returns: A filter that adds a shadow style.
Returns a filter that applies a contrast adjustment.
This filter is equivalent to the `contrast` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
- Parameters:
- amount: An amount to adjust the contrast. A value of
zero leaves the result completely gray. A value of one leaves
the result unchanged. You can use values greater than one.
- Returns: A filter that applies a contrast adjustment.
Returns a filter that applies a grayscale adjustment.
This filter is equivalent to the `grayscale` filter primitive
defined by the Scalable Vector Graphics (SVG) specification.
- Parameters:
- amount: An amount that controls the effect. A value of one
makes the image completely gray. A value of zero leaves the
result unchanged. Other values apply a linear multiplier effect.
- Returns: A filter that applies a grayscale adjustment.