Image filters
Blur, drop shadow, colour, and composed chains after rasterization.
An image filter transforms a rasterized draw or layer. Hang it on the
paint, or on a saveLayer so several shapes share one chain.
let shadow = ImageFilter::drop_shadow(
Point::new(8.0, 12.0),
6.0,
6.0,
Color::rgba(0.0, 0.0, 0.0, 0.55),
);
let soften = ImageFilter::blur(1.5, 1.5);
paint.image_filter = Some(ImageFilter::compose(shadow, soften));const shadow = ImageFilter.dropShadow(8, 12, 6, 6, 0, 0, 0, 0.55);
const soften = ImageFilter.blur(1.5, 1.5);
paint.setImageFilter(ImageFilter.compose(shadow, soften));A lime card with a drop shadow.
Kinds
| Filter | Effect |
|---|---|
Blur | Gaussian in local x and y |
Color | A ColorFilter after rasterization |
DropShadow | Blurred, offset, recoloured alpha under the original |
Compose | inner first, then outer |
Matrix | The pixels moved by a matrix, read with the given filtering |
Consecutive blurs merge in device space. A rotation mixes the axes before they combine.
A matrix filter moves pixels that are already drawn, so a scale enlarges them instead of drawing the content again at the new size. The matrix is in local units, like a blur's sigma, so a scale about a point of the content stays about that point. A backdrop with a matrix filter is a magnifier:
let lens = Matrix::translation(120.0, 80.0)
.then(&Matrix::scale(2.0, 2.0))
.then(&Matrix::translation(-120.0, -80.0));
builder.save_layer_backdrop(
Some(Rect::new(80.0, 40.0, 80.0, 80.0)),
&Paint::default(),
Backdrop::new(ImageFilter::matrix(lens, Sampling::default())),
);
builder.restore();const lens = ImageFilter.matrix(
new Float32Array([2, 0, 0, 2, -120, -80]),
Filter.Linear,
MipmapMode.None,
);Order with colour filter and mask blur
On a draw's effect layer, colour filter runs first, then blur.
On a save_layer, image filter (including blur) runs first, then colour
filter — so a translating matrix acts on the halo.
See Paint for which field is which.
Blur, drop shadow, a colour filter, then shadow composed with a slight blur.