PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Problem with XColor.FromArgb() overload
https://forum.pdfsharp.net/viewtopic.php?f=3&t=1210
Page 1 of 1

Author:  JeffJohnson [ Fri Jun 04, 2010 3:37 pm ]
Post subject:  Problem with XColor.FromArgb() overload

When using the XColor.FromArgb(int alpha, System.Drawing.Color color) overload, the behavior is not what is expected. This static method simply creates a new XColor with this code:

Code:
return new XColor(alpha, color.R, color.G, color.B);

and I believe the intention was that the constructor XColor(byte alpha, byte red, byte green, byte blue) would be called, but as I step through it in Visual Studio 2008 SP1 I see that this is not the case. The constructor XColor(double cyan, double magenta, double yellow, double black) is getting called instead, probably because alpha is an int and not a byte. This results in completely incorrect color values in the resulting XColor.

I corrected this by simply casting alpha to byte in the code above. I don't really know why alpha was made an int in the first place. I recommend that you provide another overload that takes a byte and deprecate the int version (as well as adding the cast).

To reproduce the problem as it exists, simply run this line of code:

Code:
XColor dummy = XColor.FromArgb(128, Color.Blue);

You'll get black instead of blue and the XColor will have the CMYK color space instead of RGB. I'm using version 1.31 of PDFsharp.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/