Struct Bitmap

Source
pub struct Bitmap {
    pub handle: HANDLE,
    /* private fields */
}
Expand description

A wrapper over a bitmap file (*.bmp)

Note that Bitmap object are only used as display resources (ie: it’s impossible to read pixels or resized it). If those features are needed, see the image-decoder feature.

To display a bitmap in an application, see the ImageFrame control.

By default, bitmap resources do not support transparency BUT if image-decoder is enabled, bitmaps can be loaded from any file type supported natively by Windows: JPEG, PNG, BMP, ICO, DDS, TIFF.

Bitmaps can be converted to icons using the “copy_as_icon” function.

Builder parameters:

  • source_file: The source of the bitmap if it is a file.
  • source_bin: The source of the bitmap if it is a binary blob. For example using include_bytes!("my_icon.bmp").
  • source_system: The source of the bitmap if it is a system resource (see OemBitmap)
  • source_embed: The source of the bitmap if it is stored in an embedded file
  • source_embed_id: The number identifier of the icon in the embedded file
  • source_embed_str: The string identifier of the icon in the embedded file
  • size: Optional. Resize the image to this size.
  • strict: Use a system placeholder instead of panicking if the image source do no exists.

Example:

use native_windows_gui as nwg;

fn load_bitmap() -> nwg::Bitmap {
    nwg::Bitmap::from_file("Hello.bmp", true).unwrap()
}

fn load_bitmap_builder() -> nwg::Bitmap {
    let mut bitmap = nwg::Bitmap::default();

    nwg::Bitmap::builder()
        .source_file(Some("Hello.bmp"))
        .strict(true)
        .build(&mut bitmap)
        .unwrap();

    bitmap
}

Fields§

§handle: HANDLE

Implementations§

Source§

impl Bitmap

Source

pub fn builder<'a>() -> BitmapBuilder<'a>

Source

pub fn from_system(sys_bitmap: OemBitmap) -> Bitmap

Single line helper function over the bitmap builder api.

Use system resources.

Source

pub fn from_file(path: &str, strict: bool) -> Result<Bitmap, NwgError>

Single line helper function over the bitmap builder api.

Use a file resource.

Source

pub fn from_bin(bin: &[u8]) -> Result<Bitmap, NwgError>

Single line helper function over the bitmap builder api.

Use a binary resource.

Source

pub fn from_embed( embed: &EmbedResource, embed_id: Option<usize>, embed_str: Option<&str>, ) -> Result<Bitmap, NwgError>

Single line helper function over the bitmap builder api.

Use an embedded resource. Either embed_id or embed_str must be defined, not both.

Requires the embed-resource feature.

Source

pub fn copy_as_icon(&self) -> Icon

Creates a new icon from the bitmap data.

Panics if the bitmap is not initialized

Trait Implementations§

Source§

impl Default for Bitmap

Source§

fn default() -> Bitmap

Returns the “default value” for a type. Read more
Source§

impl Drop for Bitmap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Bitmap

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Bitmap

§

impl RefUnwindSafe for Bitmap

§

impl !Send for Bitmap

§

impl !Sync for Bitmap

§

impl Unpin for Bitmap

§

impl UnwindSafe for Bitmap

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