Instance Method インスタンスメソッド

addFilter(_:options:)

Adds a filter that applies to subsequent drawing operations.

Declaration 宣言

mutating func addFilter(_ filter: GraphicsContext.Filter, options: GraphicsContext.FilterOptions = FilterOptions())

Parameters パラメータ

filter

A graphics context filter that you create by calling one of the GraphicsContext.Filter factory methods.

options

A set of options from GraphicsContext.FilterOptions that you can use to configure filter operations.

Discussion 議論

To draw with filtering, SwiftUI:

  • Rasterizes the drawing operation to an implicit transparency layer without blending, adjusting opacity, or applying any clipping.

  • Applies the filter to the layer containing the rasterized image.

  • Composites the layer onto the background, using the context’s current blend mode, opacity setting, and clip shapes.

When SwiftUI draws with a filter, the blend mode might apply to regions outside the drawing operation’s intrinsic shape, but inside its clip shape. That might result in unexpected behavior for certain blend modes like copy, where the drawing operation completely overwrites the background even if the source alpha is zero.

See Also 参照

Filtering