Skip to main content

WriteableBitmap

Struct WriteableBitmap 

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

Holds a writeable bitmap image.

Implementations§

Source§

impl WriteableBitmap

Source

pub fn new( size: PixelSize, dpi: Vector, format: Option<PixelFormat>, alpha_format: Option<AlphaFormat>, ) -> WriteableBitmap

Creates a bitmap of the given size, in pixels, and DPI. The formats default to the backend’s default formats.

Panics when the size is not positive or the pixel format is not supported.

Source

pub fn from_pixels( format: PixelFormat, alpha_format: AlphaFormat, data: &[u8], size: PixelSize, dpi: Vector, stride: i32, ) -> WriteableBitmap

Creates a writeable bitmap from a pixel data copy: data holds rows of format pixels, stride bytes apart.

Panics when stride is too small for a row.

Source

pub fn format(&self) -> Option<PixelFormat>

The pixel format of the bitmap.

Source

pub fn lock(&self) -> Rc<dyn ILockedFramebuffer>

Locks the pixel data of the bitmap and returns a framebuffer that can be used to read and write the pixels. The changes are committed when the framebuffer is disposed.

Source

pub fn copy_pixels( &self, source_rect: PixelRect, buffer: &mut [u8], stride: i32, )

Copies the pixels of source_rect into buffer, whose rows are stride bytes apart. An empty source_rect selects the whole bitmap.

Source

pub fn decode(stream: &mut dyn Read) -> Result<WriteableBitmap>

Loads a writeable bitmap from a stream.

Source

pub fn decode_to_width( stream: &mut dyn Read, width: i32, interpolation_mode: BitmapInterpolationMode, ) -> Result<WriteableBitmap>

Loads a writeable bitmap from a stream, decoded to the specified width maintaining aspect ratio.

Source

pub fn decode_to_height( stream: &mut dyn Read, height: i32, interpolation_mode: BitmapInterpolationMode, ) -> Result<WriteableBitmap>

Loads a writeable bitmap from a stream, decoded to the specified height maintaining aspect ratio.

Methods from Deref<Target = Bitmap>§

Source

pub fn create_scaled_bitmap( &self, destination_size: PixelSize, interpolation_mode: BitmapInterpolationMode, ) -> Bitmap

Creates a bitmap scaled to the specified size from the current bitmap.

Source

pub fn dispose(&self)

Releases the bitmap’s reference to the platform bitmap.

Source

pub fn dpi(&self) -> Vector

The dots per inch (DPI) of the image.

Source

pub fn size(&self) -> Size

The size of the image, in device independent pixels.

Source

pub fn pixel_size(&self) -> PixelSize

The size of the bitmap, in device pixels.

Source

pub fn platform_impl(&self) -> &RefCounted<SharedBitmapImpl>

The platform-specific bitmap implementation.

Source

pub fn save_to_file( &self, file_name: &str, options: &BitmapEncoderOptions, ) -> Result<()>

Saves the bitmap to a file.

Source

pub fn save( &self, stream: &mut dyn Write, options: &BitmapEncoderOptions, ) -> Result<()>

Saves the bitmap to a stream.

Source

pub fn format(&self) -> Option<PixelFormat>

The pixel format of the bitmap, if its pixels can be read.

Source

pub fn alpha_format(&self) -> Option<AlphaFormat>

The alpha format of the bitmap, if its pixels can be read.

Source

pub fn copy_pixels( &self, source_rect: PixelRect, buffer: &mut [u8], stride: i32, )

Copies the pixels of source_rect into buffer, whose rows are stride bytes apart. An empty source_rect selects the whole bitmap.

Panics when the pixels of the bitmap cannot be read, when the bitmap was converted from another pixel format on creation, or when the rectangle, stride or buffer are out of range.

Source

pub fn copy_pixels_to_framebuffer(&self, buffer: &dyn ILockedFramebuffer)

Copies the pixels of the bitmap into a locked framebuffer, converting them to its pixel and alpha formats.

Panics when the pixels of the bitmap cannot be read.

Trait Implementations§

Source§

impl Deref for WriteableBitmap

Source§

type Target = Bitmap

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Bitmap

Dereferences the value.
Source§

impl IBitmap for WriteableBitmap

Source§

fn dpi(&self) -> Vector

The dots per inch (DPI) of the image. Read more
Source§

fn pixel_size(&self) -> PixelSize

The size of the bitmap, in device pixels.
Source§

fn platform_impl(&self) -> &RefCounted<SharedBitmapImpl>

The platform-specific bitmap implementation.
Source§

fn save( &self, stream: &mut dyn Write, options: &BitmapEncoderOptions, ) -> Result<()>

Saves the bitmap to a stream.
Source§

fn dispose(&self)

Releases the bitmap.
Source§

impl IImage for WriteableBitmap

Source§

fn size(&self) -> Size

The size of the image, in device independent pixels.
Source§

fn draw( &self, context: &mut DrawingContext<'_>, source_rect: Rect, dest_rect: Rect, )

Draws the image to a drawing context: the part of the image inside source_rect is drawn into dest_rect.
Source§

fn as_any(&self) -> &dyn Any

The implementing value, for downcasts to concrete image types. For image classes use as_object.
Source§

fn as_bitmap(&self) -> Option<&dyn IBitmap>

The image viewed as a bitmap, when it is one.
Source§

fn as_object(&self) -> Option<&FerroObject>

The object behind the image when it is an image class.
Source§

fn as_affects_render(&self) -> Option<&dyn IAffectsRender>

The image viewed as IAffectsRender, when it can change.
Source§

impl IImageBrushSource for WriteableBitmap

Source§

fn bitmap(&self) -> Option<&RefCounted<SharedBitmapImpl>>

The counted reference to the platform bitmap, while it is alive.
Source§

fn get_bitmap(&self) -> Option<Arc<SharedBitmapImpl>>

The platform bitmap, while it is alive.

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.