MCPcopy Create free account
hub / github.com/OpenActionAPI/rust-elgato-streamdeck / from_image

Method from_image

src/images.rs:87–101  ·  view source on GitHub ↗

Converts image to image rect

(image: DynamicImage)

Source from the content-addressed store, hash-verified

85impl ImageRect {
86 /// Converts image to image rect
87 pub fn from_image(image: DynamicImage) -> Result<ImageRect, StreamDeckError> {
88 let (image_w, image_h) = image.dimensions();
89
90 let image_data = image.into_rgb8().to_vec();
91
92 let mut buf = Vec::new();
93 let mut encoder = JpegEncoder::new_with_quality(&mut buf, 90);
94 encoder.encode(&image_data, image_w, image_h, ColorType::Rgb8.into())?;
95
96 Ok(ImageRect {
97 w: image_w as u16,
98 h: image_h as u16,
99 data: buf,
100 })
101 }
102
103 /// Converts image to image rect, can be safely ran inside [multi_thread](tokio::runtime::Builder::new_multi_thread) runtime
104 #[cfg(feature = "async")]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected