[Mono-bugs] [Bug 495516] DrawImage and PNGCodec broken w.r.t. alpha channel

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed May 20 12:46:01 EDT 2009


User alexander.shulgin at yessoftware.com added comment

Alex Shulgin <alexander.shulgin at yessoftware.com> changed:

           What    |Removed                     |Added
 Attachment #291604|0                           |1
        is obsolete|                            |

--- Comment #3 from Alex Shulgin <alexander.shulgin at yessoftware.com>  2009-05-20 10:45:59 MDT ---
Created an attachment (id=293381)
 --> (http://bugzilla.novell.com/attachment.cgi?id=293381)
Updated libgdiplus patch.

After another take on this problem I've found one missing piece in the puzzle.

Turned out that Mono doesn't implement pixel format conversion in
Bitmap.GetPixel/SetPixel and Bitmap.LockBits/UnlockBits for Format32bppPArgb,
while .net does.  It works this way:

- if you create a bitmap with PARGB format, on every call to GetPixel or
SetPixel pixel data is converted to/from ARGB;

- if you request conversion to/from PARGB in LockBits, the pixel data in scan0
comes converted to requested format and changes are "commited" to bitmap in the
original format upon call to UnlockBits.

Some sample code:

using System;

using System.Drawing;

using System.Drawing.Imaging;

namespace bmppixformat


    class Program


        static void Main()


            Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format32bppPArgb);

            bmp.SetPixel(0, 0, Color.FromArgb(127, 255, 191, 160));

            Console.WriteLine(bmp.GetPixel(0, 0));

/* Change only alpha component of the pixel using low-level LockBits interface
and observe the result with GetPixel later. */
            BitmapData data = bmp.LockBits(new Rectangle(new Point(0, 0),





                byte* scan0 = (byte*) data.Scan0;

                Console.WriteLine("scan0: {0} {1} {2} {3}", scan0[0], scan0[1],
scan0[2], scan0[3]);

                scan0[3] = 200;

                Console.WriteLine("scan0: {0} {1} {2} {3}", scan0[0], scan0[1],
scan0[2], scan0[3]);



            Console.WriteLine(bmp.GetPixel(0, 0));




After applying my patch, I get the following output from this code:

Color [A=127, R=255, G=190, B=158]
scan0: 158 190 255 127
scan0: 158 190 255 200
Color [A=200, R=255, G=189, B=156]

Which means we've successfully replaced the alpha component and didn't touched
(well, almost ;) the color components.

I think this change finishes the patch on PARGB handling in libgdiplus.  Next
is adding unit-tests. :)

Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list