Graphics.DrawImage with ImageAttributes for transparency does not work with 24bpp bitmaps. The alpha values are just multiplied into the color, and you end up with a dark image.
The below code:
var bitmap = new Bitmap(100, 100);
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.Clear(Color.White);
var redBitmap = new Bitmap(50, 50, PixelFormat.Format24bppRgb);
using (var redGraphics = Graphics.FromImage(redBitmap))
{
redGraphics.Clear(Color.Red);
}
var destRect = new RectangleF(25, 25, 50, 50);
var srcRect = new RectangleF(0, 0, 50, 50);
PointF[] destRectanglePoints =
{
new(destRect.Left, destRect.Top),
new(destRect.Right, destRect.Top),
new(destRect.Left, destRect.Bottom)
};
var attributes = new ImageAttributes();
attributes.SetColorMatrix(new ColorMatrix { Matrix33 = 0.5f });
graphics.DrawImage(redBitmap, destRectanglePoints, srcRect, GraphicsUnit.Pixel, attributes);
}
Graphics.DrawImage with ImageAttributes for transparency does not work with 24bpp bitmaps. The alpha values are just multiplied into the color, and you end up with a dark image.
The below code:
Renders like this:
It is expected to render like this:
It works as expected for 32 but pixel formats.
We are building libgdiplus from main.