Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphics.DrawImage with ImageAttributes for transparency does not work with 24bpp bitmaps #727

Open
jhergens opened this issue Dec 6, 2021 · 0 comments

Comments

@jhergens
Copy link

jhergens commented Dec 6, 2021

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);
}

Renders like this:
screenshot-1

It is expected to render like this:
screenshot-2

It works as expected for 32 but pixel formats.

We are building libgdiplus from main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant