Search code examples
c#monogdi+system.drawing

Mono System.Drawing, Transparent pixels turn semi-gray


I'm using Mono 4.6.1 on, using System.Drawing I want to overlay these two images (imgur album). But the finished result looks like this, with the first image having a slightly white tint. Setting a background color before rendering reveals that the transparent parts of the cardBack image are not blended correctly.

        const int width = 764;
        const float s = width / 764;

        var cardBack = new Bitmap(@"assets/mHunter.png");
        var cardArt = new Bitmap(@"CardArt/Full/AT_007.png");


        using (var bmp = new Bitmap(cardBack.Width, cardBack.Height, PixelFormat.Format32bppArgb))
        using (var gr = Graphics.FromImage(bmp)) {

            //Draw card art clipped by type
            var clippingRegion = CreateEllipseRegion(s);
            //gr.SetClip(clippingRegion);
            //ctx.drawImage(t, 0, 0, t.width, t.height, 100 * s, 75 * s, 590 * s, 590 * s);
            gr.DrawImage(cardArt, 100 * s, 75 * s, 590 * s, 590 * s);
            //gr.ResetClip();

            gr.DrawImage(cardBack,0, 0);

            bmp.Save("/tmp/result.png", ImageFormat.Png);
        }

Solution

  • It turns out that the cardBack images uses an indexed color mode, after changing it to RGB using GIMP, it now blends correctly.