# RasterAnimationEncoder

Encodes complete RGBA canvases as GIF or animated PNG using the managed raster engines.

 Class  

`ChartForgeX.Raster`

**Namespace**

`ChartForgeX.Raster`

**Assembly**

`ChartForgeX`

**Source**

[RasterAnimationEncoder.cs:29](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Raster/RasterAnimationEncoder.cs#L29)

**Modifiers**

static

Encodes complete RGBA canvases as GIF or animated PNG using the managed raster engines.

## Inheritance

- object
- RasterAnimationEncoder

## Remarks

Frames must share their dimensions. Both containers preserve zero frame delays. GIF rounds cumulative positive frame boundaries to the nearest 10 milliseconds, with a 10 millisecond minimum and 655.35 second maximum, and treats alpha below 128 as transparent. APNG preserves representable rational durations and otherwise rounds to a supported fraction, with a 65,535 second maximum. Encoder working buffers and returned output share a 256 MiB ceiling; caller-owned input pixel buffers are excluded. The frame list and pixel buffers must remain unchanged while encoding.

## Guides & Samples

Authored walkthroughs and practical samples linked to this API.

- [Encode RGBA animation frames](/docs/raster-animation/) Guide 
  
  GIF/APNG timing, source lifetime and bounded encoding.

 Filter members   

    Show inherited   

 

## Methods

 Encode 2 overloads 

 `public static byte[] Encode(IReadOnlyList<RasterAnimationFrame> frames, RasterAnimationFormat format, RasterAnimationOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-encode-collections-generic-ireadonlylist-chartforgex-raster-rasteranimationframe-chartforgex-raster-rasteranimationformat-chartforgex-raster-rasteranimationoptions-threading-cancellationtoken) 

[RasterAnimationEncoder.cs:29](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Raster/RasterAnimationEncoder.cs#L29)

Encodes frames into a new byte array.

Parameters

**frames System.Collections.Generic.IReadOnlyList<ChartForgeX.Raster.RasterAnimationFrame> required**

One or more complete RGBA frames with matching dimensions.

**format ChartForgeX.Raster.RasterAnimationFormat required**

The GIF or APNG container.

**options ChartForgeX.Raster.RasterAnimationOptions? = null optional**

Playback and encoding options; omitted options repeat indefinitely with PNG compression level 6.

**cancellationToken System.Threading.CancellationToken = default optional**

Cancels validation and encoding between units of work.

Returns

 `byte[]` The encoded animation. 

 `public static byte[] Encode(RasterAnimationSource source, RasterAnimationFormat format, RasterAnimationOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-encode-chartforgex-raster-rasteranimationsource-chartforgex-raster-rasteranimationformat-chartforgex-raster-rasteranimationoptions-threading-cancellationtoken) 

[RasterAnimationEncoder.Streaming.cs:12](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Raster/RasterAnimationEncoder.Streaming.cs#L12)

Encodes a repeatable producer with memory bounded independently of frame count.

Parameters

**source ChartForgeX.Raster.RasterAnimationSource required**

**format ChartForgeX.Raster.RasterAnimationFormat required**

**options ChartForgeX.Raster.RasterAnimationOptions? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

 `byte[]` 

 WriteTo 2 overloads 

 `public static void WriteTo(Stream stream, IReadOnlyList<RasterAnimationFrame> frames, RasterAnimationFormat format, RasterAnimationOptions? options = null, CancellationToken cancellationToken = default)` [#](#member-65ff77e1c7d3708825d0bfbc) 

[RasterAnimationEncoder.cs:53](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Raster/RasterAnimationEncoder.cs#L53)

Writes an animation to a caller-owned writable stream and leaves that stream open.

Parameters

**stream System.IO.Stream required**

The destination stream. Validation completes before any bytes are written.

**frames System.Collections.Generic.IReadOnlyList<ChartForgeX.Raster.RasterAnimationFrame> required**

One or more complete RGBA frames with matching dimensions.

**format ChartForgeX.Raster.RasterAnimationFormat required**

The GIF or APNG container.

**options ChartForgeX.Raster.RasterAnimationOptions? = null optional**

Playback and encoding options; omitted options repeat indefinitely with PNG compression level 6.

**cancellationToken System.Threading.CancellationToken = default optional**

Cancels validation and encoding between units of work.

 `public static void WriteTo(Stream stream, RasterAnimationSource source, RasterAnimationFormat format, RasterAnimationOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-writeto-io-stream-chartforgex-raster-rasteranimationsource-chartforgex-raster-rasteranimationformat-chartforgex-raster-rasteranimationoptions-threading-cancellationtoken) 

[RasterAnimationEncoder.Streaming.cs:26](https://github.com/EvotecIT/ChartForgeX/blob/main/ChartForgeX/Raster/RasterAnimationEncoder.Streaming.cs#L26)

Writes a repeatable producer to a caller-owned stream, leaving it open.

Parameters

**stream System.IO.Stream required**

**source ChartForgeX.Raster.RasterAnimationSource required**

**format ChartForgeX.Raster.RasterAnimationFormat required**

**options ChartForgeX.Raster.RasterAnimationOptions? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

## Inherited Methods

 `public virtual bool Equals(object? obj)` [#](#method-equals-object) 

Inherited from object

Parameters

**obj object? required**

Returns

 `bool` 

 `public virtual int GetHashCode()` [#](#method-gethashcode) 

Inherited from object

Returns

 `int` 

 `public Type GetType()` [#](#method-gettype) 

Inherited from object

Returns

 `Type` 

 `public virtual string? ToString()` [#](#method-tostring) 

Inherited from object

Returns

 `string?` 

<!-- PowerForge markdown artifact sha256:A9AF858E25B749E612F4B210B462FFDAF128BA92E6EF448266D3C1C81D22B996 -->
