diff options
author | 2020-03-24 19:08:21 +0100 | |
---|---|---|
committer | 2020-03-24 19:08:21 +0100 | |
commit | e77fa175aa0eaf62be4ebafbd8e0dbc5df18f006 (patch) | |
tree | 78608f77c6db3ff1e61a58008bd54d114f32352c /native/src/widget/image.rs | |
parent | 7cb1452d29ddfdcd29fd7ecc7c96a79ea2681fce (diff) | |
parent | fd7d9622e333a0a2cd5c2e8e6cc38cc09d7981e4 (diff) | |
download | iced-e77fa175aa0eaf62be4ebafbd8e0dbc5df18f006.tar.gz iced-e77fa175aa0eaf62be4ebafbd8e0dbc5df18f006.tar.bz2 iced-e77fa175aa0eaf62be4ebafbd8e0dbc5df18f006.zip |
Merge branch 'master' into feature/text-selection
Diffstat (limited to '')
-rw-r--r-- | native/src/widget/image.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 200401f9..5b067687 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -18,7 +18,7 @@ use std::{ /// ``` /// /// <img src="https://github.com/hecrj/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true" width="300"> -#[derive(Debug)] +#[derive(Debug, Hash)] pub struct Image { handle: Handle, width: Length, @@ -125,6 +125,21 @@ impl Handle { Self::from_data(Data::Path(path.into())) } + /// Creates an image [`Handle`] containing the image pixels directly. This + /// function expects the input data to be provided as a `Vec<u8>` of BGRA + /// pixels. + /// + /// This is useful if you have already decoded your image. + /// + /// [`Handle`]: struct.Handle.html + pub fn from_pixels(width: u32, height: u32, pixels: Vec<u8>) -> Handle { + Self::from_data(Data::Pixels { + width, + height, + pixels, + }) + } + /// Creates an image [`Handle`] containing the image data directly. /// /// This is useful if you already have your image loaded in-memory, maybe @@ -188,6 +203,16 @@ pub enum Data { /// In-memory data Bytes(Vec<u8>), + + /// Decoded image pixels in BGRA format. + Pixels { + /// The width of the image. + width: u32, + /// The height of the image. + height: u32, + /// The pixels. + pixels: Vec<u8>, + }, } impl std::fmt::Debug for Data { @@ -195,6 +220,9 @@ impl std::fmt::Debug for Data { match self { Data::Path(path) => write!(f, "Path({:?})", path), Data::Bytes(_) => write!(f, "Bytes(...)"), + Data::Pixels { width, height, .. } => { + write!(f, "Pixels({} * {})", width, height) + } } } } |