pub struct ImageEncoder { /* private fields */ }Expand description
Encodes raw image buffers into encoded bytes for common formats.
Supports saving as PNG, JPEG, GIF, TIFF, BMP, and JPEG XR when the input color format is compatible.
ยงExample
use windows_capture::encoder::{ImageEncoder, ImageEncoderPixelFormat, ImageFormat};
let width = 320u32;
let height = 240u32;
// BGRA8 buffer (e.g., from a frame)
let bgra = vec![0u8; (width * height * 4) as usize];
let png_bytes = ImageEncoder::new(ImageFormat::Png, ImageEncoderPixelFormat::Bgra8)
.unwrap()
.encode(&bgra, width, height)
.unwrap();
std::fs::write("example.png", png_bytes).unwrap();Implementationsยง
Sourceยงimpl ImageEncoder
impl ImageEncoder
Sourcepub fn new(
format: ImageFormat,
pixel_format: ImageEncoderPixelFormat,
) -> Result<Self, ImageEncoderError>
pub fn new( format: ImageFormat, pixel_format: ImageEncoderPixelFormat, ) -> Result<Self, ImageEncoderError>
Constructs a new ImageEncoder.
Sourcepub fn encode(
&self,
image_buffer: &[u8],
width: u32,
height: u32,
) -> Result<Vec<u8>, ImageEncoderError>
pub fn encode( &self, image_buffer: &[u8], width: u32, height: u32, ) -> Result<Vec<u8>, ImageEncoderError>
Encodes the provided pixel buffer into the configured output ImageFormat.
The input buffer must match the specified source crate::settings::ColorFormat
and dimensions. For packed 8-bit formats (e.g., crate::settings::ColorFormat::Bgra8),
the buffer length should be width * height * 4.
ยงErrors
ImageEncoderError::UnsupportedFormatwhen the source format is unsupported for images (e.g.,crate::settings::ColorFormat::Rgba16F)ImageEncoderError::WindowsErrorwhen Windows Imaging API calls failImageEncoderError::IntConversionErroron integer conversion failures
Auto Trait Implementationsยง
impl Freeze for ImageEncoder
impl RefUnwindSafe for ImageEncoder
impl Send for ImageEncoder
impl Sync for ImageEncoder
impl Unpin for ImageEncoder
impl UnsafeUnpin for ImageEncoder
impl UnwindSafe for ImageEncoder
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more