ImageEncoder

Trait ImageEncoder 

Source
pub trait ImageEncoder {
    // Required method
    fn write_image(
        self,
        buf: &[u8],
        width: u32,
        height: u32,
        color_type: ExtendedColorType,
    ) -> ImageResult<()>;

    // Provided methods
    fn set_icc_profile(
        &mut self,
        icc_profile: Vec<u8>,
    ) -> Result<(), UnsupportedError> { ... }
    fn set_exif_metadata(
        &mut self,
        exif: Vec<u8>,
    ) -> Result<(), UnsupportedError> { ... }
}
Expand description

The trait all encoders implement

Required Methods§

Source

fn write_image( self, buf: &[u8], width: u32, height: u32, color_type: ExtendedColorType, ) -> ImageResult<()>

Writes all the bytes in an image to the encoder.

This function takes a slice of bytes of the pixel data of the image and encodes them. Just like for [ImageDecoder::read_image], no particular alignment is required and data is expected to be in native endian. The implementation will reorder the endianness as necessary for the target encoding format.

§Panics

Panics if width * height * color_type.bytes_per_pixel() != buf.len().

Provided Methods§

Source

fn set_icc_profile( &mut self, icc_profile: Vec<u8>, ) -> Result<(), UnsupportedError>

Set the ICC profile to use for the image.

This function is a no-op for formats that don’t support ICC profiles. For formats that do support ICC profiles, the profile will be embedded in the image when it is saved.

§Errors

This function returns an error if the format does not support ICC profiles.

Source

fn set_exif_metadata(&mut self, exif: Vec<u8>) -> Result<(), UnsupportedError>

Set the EXIF metadata to use for the image.

This function is a no-op for formats that don’t support EXIF metadata. For formats that do support EXIF metadata, the metadata will be embedded in the image when it is saved.

§Errors

This function returns an error if the format does not support EXIF metadata or if the encoder doesn’t implement saving EXIF metadata yet.

Implementors§

Source§

impl<W> ImageEncoder for OpenExrEncoder<W>
where W: Write + Seek,

Available on crate feature exr only.
Source§

impl<W: Write + Seek> ImageEncoder for TiffEncoder<W>

Available on crate feature tiff only.
Source§

impl<W: Write> ImageEncoder for AvifEncoder<W>

Available on crate feature avif and (crate features avif or avif-native) only.
Source§

impl<W: Write> ImageEncoder for BmpEncoder<'_, W>

Available on crate feature bmp only.
Source§

impl<W: Write> ImageEncoder for FarbfeldEncoder<W>

Available on crate feature ff only.
Source§

impl<W: Write> ImageEncoder for GifEncoder<W>

Available on crate feature gif only.
Source§

impl<W: Write> ImageEncoder for HdrEncoder<W>

Available on crate feature hdr only.
Source§

impl<W: Write> ImageEncoder for IcoEncoder<W>

Available on crate feature ico only.
Source§

impl<W: Write> ImageEncoder for JpegEncoder<W>

Available on crate feature jpeg only.
Source§

impl<W: Write> ImageEncoder for PngEncoder<W>

Available on crate feature png only.
Source§

impl<W: Write> ImageEncoder for PnmEncoder<W>

Available on crate feature pnm only.
Source§

impl<W: Write> ImageEncoder for QoiEncoder<W>

Available on crate feature qoi only.
Source§

impl<W: Write> ImageEncoder for TgaEncoder<W>

Available on crate feature tga only.
Source§

impl<W: Write> ImageEncoder for WebPEncoder<W>

Available on crate feature webp only.