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 usinginclude_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 filesource_embed_id
: The number identifier of the icon in the embedded filesource_embed_str
: The string identifier of the icon in the embedded filesize
: 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
impl Bitmap
pub fn builder<'a>() -> BitmapBuilder<'a>
Sourcepub fn from_system(sys_bitmap: OemBitmap) -> Bitmap
pub fn from_system(sys_bitmap: OemBitmap) -> Bitmap
Single line helper function over the bitmap builder api.
Use system resources.
Sourcepub fn from_file(path: &str, strict: bool) -> Result<Bitmap, NwgError>
pub fn from_file(path: &str, strict: bool) -> Result<Bitmap, NwgError>
Single line helper function over the bitmap builder api.
Use a file resource.
Sourcepub fn from_bin(bin: &[u8]) -> Result<Bitmap, NwgError>
pub fn from_bin(bin: &[u8]) -> Result<Bitmap, NwgError>
Single line helper function over the bitmap builder api.
Use a binary resource.
Sourcepub fn from_embed(
embed: &EmbedResource,
embed_id: Option<usize>,
embed_str: Option<&str>,
) -> Result<Bitmap, NwgError>
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.
Sourcepub fn copy_as_icon(&self) -> Icon
pub fn copy_as_icon(&self) -> Icon
Creates a new icon from the bitmap data.
Panics if the bitmap is not initialized