I have a unit test which compares at least the bitmaps created by the test and a bitmap saved in the test project - which has been the output of the same test, but only run locally.
It is expected, that both bitmaps are equal, but the bitmap created on Azure Devops pipeline is different to the one created locally (size in Azure DevOps is smaller).
The bitmap is created with the nuget package SkiaSharp 2.88.7 using the following code:
public void Draw()
{
int width = _canvasSize.width / ScaleFactor;
int height = _canvasSize.height / ScaleFactor;
SKImageInfo imageInfo = new(width, height, SKColorType.Rgba8888, alphaType: SKAlphaType.Premul);
// Create a new SKBitmap with the specified dimensions
using (var bitmap = new SKBitmap(imageInfo))
{
// Create a new SKCanvas to draw the rectangle on the bitmap
using (var canvas = new SKCanvas(bitmap))
{
// Clear the canvas with a background color (optional)
canvas.Clear(SKColors.White);
// Create an SKPaint object to define the rectangle's appearance
using (var paint = new SKPaint())
{
paint.Color = SKColors.Black;
paint.Style = SKPaintStyle.Stroke;
// Bitmap is painted here ...
}
}
// Create a new mirrored bitmap with the same dimensions as the original bitmap
using (var mirroredBitmap = new SKBitmap(bitmap.Width, bitmap.Height))
{
// Create a new SKCanvas for the mirrored bitmap
using (var canvas = new SKCanvas(mirroredBitmap))
{
// Flip the canvas horizontally to create the mirror image effect
canvas.Scale(-1, 1, bitmap.Width / 2f, bitmap.Height / 2f);
// Draw the original bitmap onto the canvas (it will be mirrored)
canvas.DrawBitmap(bitmap, 0, 0);
using (var paint = new SKPaint())
{
// some other stuff is drawn here
}
}
// Save the mirrored image to a PNG file
using (var image = SKImage.FromBitmap(mirroredBitmap))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite($"C:\\Temporary\\quickstart{DateTime.Now:yyyy-MM-dd HH.mm.ss}.png"))
{
data.SaveTo(stream);
}
}
}
}
SKImage is converted into a png-file with statement "image.Encode(SKEncodedImageFormat.Png, 100)" at the end of the code sample which ends in a different result on Azure Devops.
The test project is a simple xunit project and the project that is painting the bitmap is targeted against .Net Standard 2.0.
Does anyone has an idea, what is going wrong here?