diff --git a/SpreadCheetah.Test/Images/yellow-500x500-transparent.png b/SpreadCheetah.Test/Images/yellow-500x500-transparent.png new file mode 100644 index 00000000..f35ec870 Binary files /dev/null and b/SpreadCheetah.Test/Images/yellow-500x500-transparent.png differ diff --git a/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs b/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs index 7296d4db..351a437a 100644 --- a/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs +++ b/SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs @@ -186,6 +186,37 @@ public async Task Spreadsheet_AddImage_Png() Assert.Equal("Image 1", picture.Name); } + [Fact] + public async Task Spreadsheet_AddImage_PngWithTransparentBackground() + { + // Arrange + const string reference = "B3"; + using var pngStream = EmbeddedResources.GetStream("yellow-500x500-transparent.png"); + using var outputStream = new MemoryStream(); + await using var spreadsheet = await Spreadsheet.CreateNewAsync(outputStream); + var embeddedImage = await spreadsheet.EmbedImageAsync(pngStream); + await spreadsheet.StartWorksheetAsync("Sheet 1"); + var canvas = ImageCanvas.OriginalSize(reference.AsSpan()); + + // Act + spreadsheet.AddImage(canvas, embeddedImage); + + // Assert + await spreadsheet.FinishAsync(); + SpreadsheetAssert.Valid(outputStream); + + using var workbook = new XLWorkbook(outputStream); + var worksheet = Assert.Single(workbook.Worksheets); + var picture = Assert.Single(worksheet.Pictures); + Assert.Equal(reference, picture.TopLeftCell.Address.ToString()); + Assert.Equal(XLPictureFormat.Png, picture.Format); + Assert.Equal(500, picture.OriginalWidth); + Assert.Equal(500, picture.OriginalHeight); + Assert.Equal(0, picture.Top); + Assert.Equal(0, picture.Left); + Assert.Equal("Image 1", picture.Name); + } + [Fact] public async Task Spreadsheet_AddImage_PngWithLargeResolution() { @@ -690,6 +721,4 @@ public async Task Spreadsheet_AddImage_PngWithFillCellsAndOffsets(int left, int Assert.Equal(expectedWidth, actualWidth); Assert.Equal(expectedHeight, actualHeight); } - - // TODO: Test for transparent image }