pub struct Encoder<W: Write> { /* private fields */ }Expand description
Encoder for XBM images.
Implementations§
Source§impl<W: Write> Encoder<W>
impl<W: Write> Encoder<W>
Sourcepub fn encode(
self,
buf: impl AsRef<[u8]>,
name: impl AsRef<str>,
width: u32,
height: u32,
x_hot: Option<u32>,
y_hot: Option<u32>,
) -> Result<(), Error>
pub fn encode( self, buf: impl AsRef<[u8]>, name: impl AsRef<str>, width: u32, height: u32, x_hot: Option<u32>, y_hot: Option<u32>, ) -> Result<(), Error>
Encodes the binary image buf.
0 represents a white pixel and 1 represents a black pixel.
name accepts a string which follow the specification in Unicode
Standard Annex #31, but it is recommended that name be restricted to
the ASCII subset of XID_Start and XID_Continue.
width should be a multiple of 8.
§Errors
Returns Err if an error occurs during I/O operations.
§Panics
Panics if the length of buf and the image dimensions (the width
multiplied by the height) are different.
§Examples
// "B" (8x7)
let pixels = b"\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x01\x01\x01\x00\x00\x00\
\x00\x00\x01\x00\x00\x01\x00\x00\
\x00\x00\x01\x01\x01\x00\x00\x00\
\x00\x00\x01\x00\x00\x01\x00\x00\
\x00\x00\x01\x01\x01\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00";
let mut buf = [u8::default(); 131];
let encoder = Encoder::new(buf.as_mut_slice());
encoder.encode(pixels, "image", 8, 7, None, None).unwrap();
assert_eq!(buf, *include_bytes!("../tests/data/basic.xbm"));Trait Implementations§
Source§impl<W: Write> ImageEncoder for Encoder<W>
Available on crate feature image only.
impl<W: Write> ImageEncoder for Encoder<W>
Available on crate feature
image only.Source§fn write_image(
self,
buf: &[u8],
width: u32,
height: u32,
color_type: ExtendedColorType,
) -> ImageResult<()>
fn write_image( self, buf: &[u8], width: u32, height: u32, color_type: ExtendedColorType, ) -> ImageResult<()>
Writes all the bytes in an image to the encoder. Read more
Source§fn set_icc_profile(
&mut self,
icc_profile: Vec<u8>,
) -> Result<(), UnsupportedError>
fn set_icc_profile( &mut self, icc_profile: Vec<u8>, ) -> Result<(), UnsupportedError>
Set the ICC profile to use for the image. Read more
Source§fn set_exif_metadata(&mut self, exif: Vec<u8>) -> Result<(), UnsupportedError>
fn set_exif_metadata(&mut self, exif: Vec<u8>) -> Result<(), UnsupportedError>
Set the EXIF metadata to use for the image. Read more
Auto Trait Implementations§
impl<W> Freeze for Encoder<W>where
W: Freeze,
impl<W> RefUnwindSafe for Encoder<W>where
W: RefUnwindSafe,
impl<W> Send for Encoder<W>where
W: Send,
impl<W> Sync for Encoder<W>where
W: Sync,
impl<W> Unpin for Encoder<W>where
W: Unpin,
impl<W> UnwindSafe for Encoder<W>where
W: UnwindSafe,
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