[Mono-winforms-list] DrawImage alpha blend broken in libgdiplus

Alex Shulgin alexander.shulgin at yessoftware.com
Tue Apr 7 11:05:57 EDT 2009


Hi,

I believe that alpha blending is broken in libgdiplus.

Below is sample code to demonstrate the problem.  I create the sample 
mask: a linear gradient from LT- to BR-corner with increasing opacity; 
then I create the sample background filled with red color.

After I draw the mask over the background I get all white rectangle.

This happens only on Mac & Linux, so it should be the problem in 
libgdiplus.  It's reproducible with mono-2.4 and 2.2.

Interestingly enough, if I store the mask into a file and then load it 
using Image.FromFile, DrawImage works as expected with the loaded file.

I'm also attaching two zip archives with png files saved on mac 
(incorrect behavior) and windows (expected behavior).

Am I missing something?

--
Regards,
Alex


using System;
using System.Drawing;

namespace AlphaBlend
{
     class MainClass
     {
         public static void Main(string[] args)
         {
             Bitmap mask = new Bitmap(128, 128);
             using (Graphics g = Graphics.FromImage(mask))
             {
                 for (int y = 0; y < mask.Height; ++y)
                 {
                     for (int x = 0; x < mask.Width; ++x)
                     {
                         mask.SetPixel(x, y, Color.FromArgb(x + y, 255, 
255, 255));
                     }
                 }
             }
             mask.Save("0mask.png");

             Bitmap bg = new Bitmap(mask.Width, mask.Height);
             using (Graphics g = Graphics.FromImage(bg))
             {
                 using (SolidBrush b = new SolidBrush(Color.Red))
                     g.FillRectangle(b, Rectangle.FromLTRB(0, 0, 
bg.Width, bg.Height));
                 bg.Save("1bg.png");

                 Image bmp = Image.FromFile("0mask.png");

                 g.DrawImage(/*bmp*/ mask, 0, 0);
             }
             bg.Save("2composite.png");
         }
     }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mac-dump.zip
Type: application/x-zip-compressed
Size: 1632 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20090407/c02df2a6/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: win-dump.zip
Type: application/x-zip-compressed
Size: 5481 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20090407/c02df2a6/attachment-0001.bin 


More information about the Mono-winforms-list mailing list