Skip to main content

Bitmap

Struct Bitmap 

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

Holds a bitmap image.

The types deriving from it (WriteableBitmap, RenderTargetBitmap) dereference to Bitmap; the members they override are reached through the deriving type or through IBitmap/IImage handles.

Implementations§

Source§

impl Bitmap

Source

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

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

interpolation_mode is used should a resize be necessary; upstream defaults it to high quality.

Source

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

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

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 from_file(file_name: &str) -> Result<Bitmap>

Loads a bitmap from a file.

Source

pub fn from_stream(stream: &mut dyn Read) -> Result<Bitmap>

Loads a bitmap from a stream.

Source

pub fn from_ref(platform_impl: &RefCounted<SharedBitmapImpl>) -> Bitmap

Creates a bitmap sharing a platform bitmap: takes another reference to it.

Source

pub fn from_impl(platform_impl: Arc<SharedBitmapImpl>) -> Bitmap

Creates a bitmap owning a platform bitmap.

Source

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

Creates a bitmap from pixel data: stride * size.height bytes of format/alpha_format pixels.

A format the backend cannot hold is converted to RGBA8888.

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 IBitmap for Bitmap

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 Bitmap

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 Bitmap

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.
Source§

impl MarkupTyped for Bitmap

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl PartialEq for Bitmap

Bitmaps compare by identity (reference equality), so that their handles can be held in untyped values.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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<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.