Skip to main content

Pixmap

Struct Pixmap 

Source
pub struct Pixmap { /* private fields */ }
Expand description

Bitmap: width × height RGBA pixels, premultiplied alpha.

Implementations§

Source§

impl Pixmap

Source

pub fn decode_png<R: Read>(reader: R) -> Result<Pixmap>

Decodes PNG from an arbitrary stream into a Pixmap (premultiplied RGBA). Palette/grayscale/16-bit are reduced to 8-bit RGBA.

Source

pub fn from_png_file(path: impl AsRef<Path>) -> Result<Pixmap>

Loads a Pixmap from a PNG file.

Source§

impl Pixmap

Source

pub fn encode_png<W: Write>(&self, writer: W) -> Result<()>

Encodes the image into PNG (8-bit, RGBA with straight alpha) to an arbitrary stream.

Source

pub fn save_png(&self, path: impl AsRef<Path>) -> Result<()>

Saves the image to a PNG file, creating parent directories if necessary.

Source§

impl Pixmap

Source

pub fn new(width: u32, height: u32) -> Option<Pixmap>

Creates a transparent image. None for zero dimensions or overflow.

Source

pub fn width(&self) -> u32

Getter for getting the width size

Source

pub fn height(&self) -> u32

Getter for getting the height size

Source

pub fn data(&self) -> &[u8]

Raw RGBA bytes (premultiplied), 4 per pixel.

Source

pub fn data_mut(&mut self) -> &mut [u8]

Mutable access to raw RGBA bytes (premultiplied), 4 per pixel.

Source

pub fn take(self) -> Vec<u8>

Takes the buffer, consuming the pixmap.

Source

pub fn pixel(&self, x: u32, y: u32) -> Option<PremultipliedColorU8>

Pixel color (premultiplied). None outside the image.

Source

pub fn fill(&mut self, color: Color)

Fills the image completely with color (without blending).

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Pixmap

Source§

fn clone(&self) -> Pixmap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.