Class JxlLayer
A JPEG XL frame before blending, from ReadLayers(string, ReaderOptions?, EgamiContext?), or one to write with WriteLayers(string, int, int, IReadOnlyList<JxlLayer>, JxlWriterOptions?, EgamiContext?).
public sealed class JxlLayer : IDisposable
- Inheritance
-
JxlLayer
- Implements
- Inherited Members
Examples
// An animation loads as its frames, blended onto the canvas, each with its delay.
using Raster animation = Raster.Load("sprite.jxl");
int frames = animation.FrameCount;
// The layers before blending, for an editor: each at its own size and place.
IReadOnlyList<JxlLayer> layers = JxlImage.ReadLayers("sprite.jxl");
foreach (JxlLayer layer in layers)
{
Console.WriteLine($"{layer.Raster.Width}x{layer.Raster.Height} at {layer.X},{layer.Y}: {layer.Blend}, {layer.Duration.TotalMilliseconds} ms");
layer.Dispose();
}
// The preview some files carry for quick display, or null.
using Raster? preview = JxlImage.ReadPreview("duck.jxl");
// A lossy still at an eighth of its size, from its LF image alone.
using Raster thumbnail = Raster.Load("duck.jxl", options: new JxlReaderOptions { MaxDownscale = 8 });
Constructors
JxlLayer(Raster, int, int, JxlLayerBlend, TimeSpan, string?)
Creates a layer to write. The layer takes the raster: disposing the layer disposes it.
public JxlLayer(Raster raster, int x = 0, int y = 0, JxlLayerBlend blend = JxlLayerBlend.Replace, TimeSpan duration = default, string? name = null)
Parameters
rasterRasterThe layer's pixels, at its own size.
xintThe left edge on the canvas; it can be negative or reach past the canvas.
yintThe top edge on the canvas; it can be negative or reach past the canvas.
blendJxlLayerBlendHow the layer's color combines with the canvas below it.
durationTimeSpanHow long the canvas shows after this layer in an animation; zero for a layer that is not shown alone.
namestringThe layer's name, up to 1,071 bytes of UTF-8, or null for none.
Examples
// Layers for an editor: each at its own place, blended onto the ones below, and named. ReadLayers gives them back.
using Raster<Rgba8> photo = Raster.Load<Rgba8>("duck.png");
Raster<Rgba8> badge = Raster.Create<Rgba8>(120, 60, new Rgba8(255, 200, 0, 160));
List<JxlLayer> layers =
[
new(photo.As<Rgba8>(), name: "photo"),
new(badge, x: -20, y: 30, blend: JxlLayerBlend.Blend, name: "badge"),
];
JxlImage.WriteLayers("layered.jxl", photo.Width, photo.Height, layers);
foreach (JxlLayer layer in layers)
{
layer.Dispose();
}
// Load gives them blended; ReadLayers as they were written.
using Raster flat = Raster.Load("layered.jxl");
IReadOnlyList<JxlLayer> read = JxlImage.ReadLayers("layered.jxl");
Exceptions
- ArgumentNullException
rasteris null.- ArgumentOutOfRangeException
blendis not a defined mode, ordurationis negative or longer than 2³² − 1 ms.- ArgumentException
nameis longer than 1,071 bytes of UTF-8.
Properties
Blend
Gets how the layer's color combines with the canvas.
public JxlLayerBlend Blend { get; }
Property Value
Duration
Gets how long the canvas shows after this layer in an animation; zero for a layer that is not shown alone.
public TimeSpan Duration { get; }
Property Value
Name
Gets the layer's name, or an empty string.
public string Name { get; }
Property Value
Raster
Gets the layer's pixels, at its own size.
public Raster Raster { get; }
Property Value
X
Gets the left edge of the layer on the canvas; it can be negative or reach past the canvas.
public int X { get; }
Property Value
Y
Gets the top edge of the layer on the canvas.
public int Y { get; }
Property Value
Methods
Dispose()
Disposes the raster.
public void Dispose()