diff options
author | 2020-02-29 07:32:42 +0530 | |
---|---|---|
committer | 2020-02-29 07:32:42 +0530 | |
commit | 18410154289fa3262403bb2c9de3dd741fd7dda2 (patch) | |
tree | 10b7dbe1908a3fb9d804f8b770bb39732b318889 /native/src | |
parent | 96f75eae4d4d19eeff8e55201822388d34445ec6 (diff) | |
download | iced-18410154289fa3262403bb2c9de3dd741fd7dda2.tar.gz iced-18410154289fa3262403bb2c9de3dd741fd7dda2.tar.bz2 iced-18410154289fa3262403bb2c9de3dd741fd7dda2.zip |
Add support for loading already-decoded image pixels
Diffstat (limited to 'native/src')
-rw-r--r-- | native/src/widget/image.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 9b92c7f1..a1743744 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -125,6 +125,19 @@ impl Handle { Self::from_data(Data::Path(path.into())) } + /// Creates an image [`Handle`] containing the image pixels directly. + /// + /// 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 +201,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 +218,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) + } } } } |