1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 15:13:12 -04:00

epaint: Added ColorImage::from_rgba_vec constructor

This is typically used when there's an existing image buffer and memory copying is to be avoided.
This commit is contained in:
Varphone Wong
2024-02-28 09:58:03 +08:00
parent 81b7e7f05a
commit 83ee315c3c

View File

@@ -123,6 +123,16 @@ impl ColorImage {
Self { size, pixels }
}
/// Creates a [`ColorImage`] with an existing image buffer.
///
/// This is typically used when you want to avoid unnecessary memory copying by reusing an existing image buffer.
///
/// Panics if `size[0] * size[1] != pixels.len()`.
pub fn from_rgba_vec(size: [usize; 2], pixels: Vec<Color32>) -> Self {
assert_eq!(size[0] * size[1], pixels.len());
Self { size, pixels }
}
/// Create a [`ColorImage`] from flat opaque gray data.
///
/// Panics if `size[0] * size[1] != gray.len()`.