ApngEncoder

public sealed class ApngEncoder : IDisposable
Streaming encoder for Animated PNG (APNG) files. Frames are compressed and written to the output stream the moment they are added, so a complete animation never needs to reside in memory at once.

Constructors

ApngEncoder

#
public ApngEncoder(Stream stream, int loopCount = 0)
Create an encoder that writes to an existing stream. The stream must be seekable so the frame count can be back-patched once all frames are known. The caller retains ownership of the stream.
stream (Stream)Seekable, writable target stream.
loopCount (int = 0)Number of times the animation plays; 0 loops forever.

ApngEncoder

#
public ApngEncoder(string path, int loopCount = 0)
Create an encoder that writes to a file on disc.
path (string)Full path of the file to create. Any existing file is overwritten.
loopCount (int = 0)Number of times the animation plays; 0 loops forever.

Properties

FrameCount

#
public int FrameCount { get; }
Gets the number of frames written so far.

Methods

AddFrame

#
public void AddFrame(Bitmap frame, int delayMs)
Append a frame to the animation. The bitmap is compressed and written immediately, so the caller may dispose it as soon as this method returns. Every frame must share the dimensions of the first frame.
frame (Bitmap)Frame image. Must be a 32-bits-per-pixel bitmap.
delayMs (int)Duration this frame stays on screen, in milliseconds (0..65535).

Dispose

#
public void Dispose()
Finish the animation (when it holds at least one frame) and release the underlying stream if this encoder owns it.

Encode

#
public static void Encode(string path, Bitmap[] frames, int delayMs, int loopCount = 0)
Convenience helper that encodes a complete array of frames with a single uniform delay. Buffers no more than one frame at a time internally.
path (string)Full path of the file to create.
frames (Bitmap[])Frames to encode; all must share the same dimensions.
delayMs (int)Duration each frame stays on screen, in milliseconds.
loopCount (int = 0)Number of times the animation plays; 0 loops forever.

Finish

#
public void Finish()
Complete the file: back-patch the frame count, write the terminating chunk and flush the stream. Called automatically by Dispose() if it has not been invoked explicitly.