pub struct Encoder<'a, F: Write> { /* private fields */ }
Expand description
APNG Encoder
§Example
use apng_encoder::{Color, Delay, Frame, Meta};
use apng_encoder::Encoder;
use std::fs::File;
// Generate 2x2 Animated PNG (4 frames)
let meta = Meta {
width: 2,
height: 2,
color: Color::RGB(8),
frames: 4,
plays: None, // Infinite loop
};
// Delay = 1/2 (0.5) seconds
let frame = Frame {
delay: Some(Delay::new(1, 2)),
..Default::default()
};
let mut file = File::create("test-output/2x2.png").unwrap();
let mut encoder = Encoder::create(&mut file, meta).unwrap();
// RED GREEN
// BLACK BLUE
encoder.write_frame(
&[
// (x=0,y=0) (x=1,y=0)
0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00,
// (x=0,y=1) (x=1,y=1)
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
],
Some(&frame),
None,
None).unwrap();
// BLACK RED
// BLUE GREEN
encoder.write_frame(
&[
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
],
Some(&frame),
None,
None).unwrap();
// BLUE BLACK
// GREEN RED
encoder.write_frame(
&[
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00,
],
Some(&frame),
None,
None).unwrap();
// GREEN BLUE
// RED BLACK
encoder.write_frame(
&[
0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
],
Some(&frame),
None,
None).unwrap();
// !!IMPORTANT DONT FORGET!!
encoder.finish().unwrap();
Implementations§
Source§impl<'a, F: Write> Encoder<'a, F>
impl<'a, F: Write> Encoder<'a, F>
pub fn create(writer: &'a mut F, meta: Meta) -> ApngResult<Self>
pub fn finish(self) -> ApngResult<()>
pub fn write_default_image( &mut self, image_data: &[u8], filter: Option<Filter>, row_stride: Option<usize>, ) -> ApngResult<()>
pub fn write_frame( &mut self, image_data: &[u8], frame: Option<&Frame>, filter: Option<Filter>, row_stride: Option<usize>, ) -> ApngResult<()>
Auto Trait Implementations§
impl<'a, F> Freeze for Encoder<'a, F>
impl<'a, F> RefUnwindSafe for Encoder<'a, F>where
F: RefUnwindSafe,
impl<'a, F> Send for Encoder<'a, F>where
F: Send,
impl<'a, F> Sync for Encoder<'a, F>where
F: Sync,
impl<'a, F> Unpin for Encoder<'a, F>
impl<'a, F> !UnwindSafe for Encoder<'a, F>
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