Meziantou.Framework.SnapshotTesting.SkiaSharp
1.0.13
Prefix Reserved
dotnet add package Meziantou.Framework.SnapshotTesting.SkiaSharp --version 1.0.13
NuGet\Install-Package Meziantou.Framework.SnapshotTesting.SkiaSharp -Version 1.0.13
<PackageReference Include="Meziantou.Framework.SnapshotTesting.SkiaSharp" Version="1.0.13" />
<PackageVersion Include="Meziantou.Framework.SnapshotTesting.SkiaSharp" Version="1.0.13" />
<PackageReference Include="Meziantou.Framework.SnapshotTesting.SkiaSharp" />
paket add Meziantou.Framework.SnapshotTesting.SkiaSharp --version 1.0.13
#r "nuget: Meziantou.Framework.SnapshotTesting.SkiaSharp, 1.0.13"
#:package Meziantou.Framework.SnapshotTesting.SkiaSharp@1.0.13
#addin nuget:?package=Meziantou.Framework.SnapshotTesting.SkiaSharp&version=1.0.13
#tool nuget:?package=Meziantou.Framework.SnapshotTesting.SkiaSharp&version=1.0.13
Meziantou.Framework.SnapshotTesting.SkiaSharp
Meziantou.Framework.SnapshotTesting.SkiaSharp extends Meziantou.Framework.SnapshotTesting with support for SkiaSharp images, enabling snapshot validation of SKImage, SKBitmap, SKPixmap, and SKSurface objects stored as PNG, JPEG, or WebP files.
Setup
Call AddSkiaSharp() on your SnapshotSettings to register the SkiaSharp serializer and comparer:
using System.Runtime.CompilerServices;
using Meziantou.Framework.SnapshotTesting;
using Meziantou.Framework.SnapshotTesting.SkiaSharp;
internal static class SnapshotConfiguration
{
[ModuleInitializer]
internal static void Initialize()
{
SnapshotSettings.Default.AddSkiaSharp();
}
}
Then validate images from your tests:
public sealed class SampleTests
{
[Fact]
public void ValidateImage()
{
using var bitmap = SKBitmap.Decode("sample.png");
Snapshot.Validate(bitmap, SnapshotType.Png);
}
}
Register once for the whole test assembly, not inside a test method. SnapshotSettings.Default is
shared by every test in the process and its collections are not safe for concurrent modification, so
calling AddSkiaSharp() from a test races against any other test that is serializing a snapshot at
the same time. Repeated calls also append a serializer and a converter every time.
Note that SkiaSharp requires the native libraries to be available at runtime. They are included in the SkiaSharp package for Windows and macOS. On Linux, add a reference to SkiaSharp.NativeAssets.Linux.
Image comparison
By default, images are compared pixel-by-pixel (exact comparison). To allow minor rendering differences, configure a Structural Similarity Index (SSIM) threshold:
// In the module initializer shown above
SnapshotSettings.Default.AddSkiaSharp(new ImageComparisonSettings
{
SimilarityThreshold = 0.99f, // 0.0 = completely different, 1.0 = identical
});
When SimilarityThreshold is set, the images must have the same dimensions and their score must be greater than or equal to the threshold. The score is the mean SSIM over every 7×7 window of the images (uniform weights, sample covariance, K1 = 0.01, K2 = 0.03), the value scikit-image's structural_similarity(expected, actual, data_range=255, channel_axis=-1) computes with its default parameters. The R, G, and B channels are premultiplied by the alpha channel and averaged, and the score is the lower of that value and the SSIM of the alpha channel, so opacity differences are detected. Because the score is a mean, a localized difference lowers it in proportion to the area it covers: a difference confined to 1% of the image lowers it by about 0.01 at most. Fully transparent pixels are equal whatever color they hide, with both the exact and the SSIM comparison, and a snapshot that cannot be decoded does not match.
16-bit PNGs follow the same rule as the built-in ImageComparer and the ImageSharp package: the exact comparison sees every bit of every sample (an 8-bit sample v equals the 16-bit sample v × 257), and the SSIM reduces each sample to 8 bits by keeping its high byte. SkiaSharp cannot decode 16-bit samples exactly, so when the 8-bit pixels of a 16-bit PNG match, the exact comparison checks the full samples with the built-in decoder of Meziantou.Framework.SnapshotTesting.
When images do not match, the assertion message says why under the changed file: an image cannot be decoded, the images have different sizes or different pixels, or the SSIM score is below the threshold.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- Meziantou.Framework.SnapshotTesting (>= 3.1.12)
- SkiaSharp (>= 4.152.0)
-
net11.0
- Meziantou.Framework.SnapshotTesting (>= 3.1.12)
- SkiaSharp (>= 4.152.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.13 | 49 | 9/20/2026 |
| 1.0.12 | 78 | 9/15/2026 |
| 1.0.11 | 84 | 9/15/2026 |
| 1.0.10 | 89 | 9/15/2026 |
| 1.0.9 | 88 | 9/13/2026 |
| 1.0.8 | 85 | 9/11/2026 |
| 1.0.7 | 103 | 9/9/2026 |
| 1.0.6 | 101 | 9/6/2026 |
| 1.0.5 | 96 | 9/3/2026 |
| 1.0.4 | 97 | 9/3/2026 |
| 1.0.3 | 98 | 8/30/2026 |
| 1.0.2 | 102 | 8/29/2026 |
| 1.0.1 | 117 | 8/23/2026 |
| 1.0.0 | 116 | 8/17/2026 |