Converts image to image rect
(image: DynamicImage)
| 85 | impl 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")] |
nothing calls this directly
no outgoing calls
no test coverage detected