Skip to content

Commit aa9642e

Browse files
committed
[DW-34] fix GetRGBABuffer and add TestGetRGBABuffer
1 parent 36a8617 commit aa9642e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,25 @@ public void TestGetRGBBuffer()
798798
Assert.Equal(firstPixel.B, buffer[2]);
799799
}
800800

801+
[FactWithAutomaticDisplayName]
802+
public void TestGetRGBABuffer()
803+
{
804+
string imagePath = GetRelativeFilePath("checkmark.jpg");
805+
using var bitmap = new AnyBitmap(imagePath);
806+
var expectedSize = bitmap.Width * bitmap.Height * 4; // 3 bytes per pixel (RGB)
807+
808+
byte[] buffer = bitmap.GetRGBABuffer();
809+
810+
Assert.Equal(expectedSize, buffer.Length);
811+
812+
// Verify the first pixel's RGB values
813+
var firstPixel = bitmap.GetPixel(0, 0);
814+
Assert.Equal(firstPixel.R, buffer[0]);
815+
Assert.Equal(firstPixel.G, buffer[1]);
816+
Assert.Equal(firstPixel.B, buffer[2]);
817+
Assert.Equal(firstPixel.A, buffer[3]);
818+
}
819+
801820
[FactWithAutomaticDisplayName]
802821
public void Test_LoadFromRGBBuffer()
803822
{

IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ public byte[] GetRGBABuffer()
16251625
var image = _lazyImage.Value.First();
16261626
int width = image.Width;
16271627
int height = image.Height;
1628-
byte[] rgbBuffer = new byte[width * height * 3]; // 3 bytes per pixel (RGB)
1628+
byte[] rgbBuffer = new byte[width * height * 4]; // 3 bytes per pixel (RGB)
16291629
switch (image)
16301630
{
16311631
case Image<Rgba32> imageAsFormat:

0 commit comments

Comments
 (0)