pub struct Pixmap { /* private fields */ }Expand description
Bitmap: width × height RGBA pixels, premultiplied alpha.
Implementations§
Source§impl Pixmap
impl Pixmap
Sourcepub fn new(width: u32, height: u32) -> Option<Pixmap>
pub fn new(width: u32, height: u32) -> Option<Pixmap>
Creates a transparent image. None for zero dimensions or overflow.
Sourcepub fn data_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_mut(&mut self) -> &mut [u8] ⓘ
Mutable access to raw RGBA bytes (premultiplied), 4 per pixel.
Sourcepub fn pixel(&self, x: u32, y: u32) -> Option<PremultipliedColorU8>
pub fn pixel(&self, x: u32, y: u32) -> Option<PremultipliedColorU8>
Pixel color (premultiplied). None outside the image.
Sourcepub fn fill_path(
&mut self,
path: &Path,
paint: &Paint,
fill_rule: FillRule,
transform: Transform,
clip: Option<&Mask>,
)
pub fn fill_path( &mut self, path: &Path, paint: &Paint, fill_rule: FillRule, transform: Transform, clip: Option<&Mask>, )
Fills a path with a brush according to the specified rule.
If a clipping mask is specified, the coverage of each
pixel is multiplied by its value, so the shape is visible
only where the mask is non-zero—for example, within the rounded
contour of the parent. None disables clipping.
Sourcepub fn stroke_path(
&mut self,
path: &Path,
paint: &Paint,
stroke: &Stroke,
transform: Transform,
clip: Option<&Mask>,
)
pub fn stroke_path( &mut self, path: &Path, paint: &Paint, stroke: &Stroke, transform: Transform, clip: Option<&Mask>, )
Brushes a path.
If a clipping mask (see Pixmap::fill_path) is specified, the coverage
is multiplied by its value; None disables clipping.
§Limitation: Non-uniform scaling and bevel
First, the path is converted to screen coordinates, and then a stroke
of constant width Stroke::width multiplied by a single
scalar—Transform::max_scale—is constructed from it.
Therefore, rotation and uniform scale are handled correctly, but
non-uniform scaling (e.g., scale(2.0, 1.0)) or bevel will
produce a uniform (circular) thickness instead of the expected elliptical one.
A correct anisotropic stroke would require constructing the path
before the transformation and then transforming it.
Sourcepub fn fill_text(
&mut self,
font: &Font<'_>,
text: &str,
size: f32,
x: f32,
y: f32,
paint: &Paint,
transform: Transform,
clip: Option<&Mask>,
)
pub fn fill_text( &mut self, font: &Font<'_>, text: &str, size: f32, x: f32, y: f32, paint: &Paint, transform: Transform, clip: Option<&Mask>, )
Draws a string by filling its glyph outlines with a brush.
A convenience wrapper over Font::text_path + Pixmap::fill_path:
the outline of text is built at em size (in pixels) with the first
baseline origin at (x, y), then filled with paint using the non-zero
winding rule — the rule TrueType/OpenType outlines are authored for.
transform and clip behave exactly as in Pixmap::fill_path; for
example, pass Transform::from_rotate_at to draw rotated text or a
Mask to clip it. Whitespace-only or empty text draws nothing.
See the text module for the (deliberately minimal)
layout rules — single line per \n, no kerning or shaping.
Sourcepub fn draw_pixmap(
&mut self,
src: &Pixmap,
x: i32,
y: i32,
opacity: f32,
blend_mode: BlendMode,
)
pub fn draw_pixmap( &mut self, src: &Pixmap, x: i32, y: i32, opacity: f32, blend_mode: BlendMode, )
Overlays the image src on top of this one, placing its upper-left
corner at (x, y) (negative coordinates allowed), with an overall
transparency multiplier of opacity (0..=1) and blend mode of blend_mode.
Only the intersection with the canvas is processed. This is the basic primitive of pixmap-on-pixmap compositing: offscreen layers, group subtree transparency (where opacity is applied to the rendered result as a whole), and sprite overlays with arbitrary blending modes.