ConvolveMatrixEffect Class |
Namespace: Microsoft.Graphics.Canvas.Effects
public sealed class ConvolveMatrixEffect : ICanvasEffect, IGraphicsEffect, IGraphicsEffectSource, ICanvasImage, IDisposable
The ConvolveMatrixEffect type exposes the following members.
Name | Description | |
---|---|---|
ConvolveMatrixEffect | Initializes a new instance of the ConvolveMatrixEffect class. |
Name | Description | |
---|---|---|
BorderMode | Gets and sets the border mode for edge pixels. | |
BufferPrecision | Specifies what precision to use for intermediate buffers when drawing this effect. | |
CacheOutput | Enables caching the output from drawing this effect. | |
ClampOutput | If set, the effect clamps color values to between 0 and 1 before passing
them on to the next effect in the graph. If false, the effect will not clamp
values, although subsequent effects or the output surface may later clamp if
they are not of high enough precision. Default value false. | |
Divisor | After the filter kernel is applied to a pixel, the result is divided by this value. Default 1. | |
InterpolationMode |
Interpolation mode used to scale the source image to the specified KernelScale.
Default value Linear.
| |
KernelHeight | Height of the filter kernel matrix. Default value 3. | |
KernelMatrix |
The filter kernel matrix.
This array must be sized KernelWidth * KernelHeight.
Default value {0,0,0,0,1,0,0,0,0}.
| |
KernelOffset |
Shifts the filter kernel from its default position centered on the output pixel. Default value (0,0).
| |
KernelScale | Scales how the filter kernel is mapped onto the 2D source image. Default value (1,1). | |
KernelWidth | Width of the filter kernel matrix. Default value 3. | |
Name | Attaches a user-defined name string to the effect. | |
Offset | After applying the filter kernel and divisor, this offset is added to the result. Default value 0. | |
PreserveAlpha | Specifies whether the convolution filter is applied to alpha as well as the color channels. When set to false, the filter applies equally to all of the red, green, blue, and alpha channels, operating on premultiplied alpha format data. When set to true, only the color channels are filtered, while alpha values are kept unchanged. In this case the effect will temporarily unpremultiply the red, green, and blue color component values, apply the filter kernel only to the color channels, and then re-premultiply the result. Default value false. | |
Source | Gets or sets the input source for ConvolveMatrix effect. |
Name | Description | |
---|---|---|
Dispose | Releases all resources used by the effect. | |
GetBounds(ICanvasResourceCreator) | Retrieves the bounds of this ConvolveMatrixEffect. | |
GetBounds(ICanvasResourceCreator, Matrix3x2) | Retrieves the bounds of this ConvolveMatrixEffect. | |
GetInvalidRectangles | Queries what regions of the effect output have changed since it was last drawn. | |
GetRequiredSourceRectangle | Queries what part of an effect source image is needed to draw an output region. | |
GetRequiredSourceRectangles | Queries what parts of the effect source images are needed to draw an output region. | |
InvalidateSourceRectangle | Notifies the effect that one of its source images has changed. |
Supported by Win2D but not Windows.UI.Composition.
A convolve filter works by sampling a number of source pixels from around the location whose output value is being computed, weighting each sample by the corresponding value from the filter kernel matrix, and summing the results. Different filter kernels can produce a wide range of image processing effects. Although the following examples all use the default 3x3 KernelWidth and KernelHeight, this can be set to any size (note that large kernels are more expensive).
Edge detect filter:
effect.KernelMatrix = new float[] { 0, 1, 0, 1, -4, 1, 0, 1, 0, };
Emboss filter:
effect.KernelMatrix = new float[] { -2, -1, 0, -1, 1, 1, 0, 1, 2, };
Sharpen the image:
effect.KernelMatrix = new float[] { -1, -2, -1, -2, 13, -2, -1, -2, -1, };
Box blur (note that GaussianBlurEffect is usually a better way to blur an image):
effect.KernelMatrix = new float[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, }; effect.Divisor = 9;
This Windows Runtime type corresponds to the D2D Convolve matrix effect.