Page 1 of 1

Correctly convert from ColorCMYK to MagickColor

Posted: 2019-03-20T13:13:09-07:00
by rondo
I am using MagickNet-Q8-64X. I am trying to convert a cmyk color to an rgb color.

Code: Select all

ColorCMYK cmkyColor = new ColorCMYK(255, 0, 0, 0, 255);
MagickColor thisColor = cmkyColor.ToMagickColor();
When I do the above code it seems to just put the 255 from the cyan value as the red value, so I end up with red instead of cyan.
Is there a step I am missing?

Sorry if this question has already been asked. All of the posts I have came across dealt with changing the colorspace of an image, whereas I do not have an image and need to just convert a color.

Re: Correctly convert from ColorCMYK to MagickColor

Posted: 2019-03-20T16:21:15-07:00
by fmw42
I do not know Magick.NET, but your command

new ColorCMYK(255, 0, 0, 0, 255);

seems to be creating a new CMYK image with Cyan=255, Magenta=0, Yellow=0, and Black=255

For me in the command line, that comes out black.

Please show your full set of code so that the experts can properly diagnose your issue.

Re: Correctly convert from ColorCMYK to MagickColor

Posted: 2019-03-21T06:45:27-07:00
by rondo
Here is my full code

Code: Select all

ColorCMYK cmkyColor = new ColorCMYK(255, 0, 0, 0, 255);
MagickColor thisColor = cmkyColor.ToMagickColor();

Bitmap bmp = new Bitmap(10, 10);

using (Graphics g = Graphics.FromImage(bmp))
{
	SolidBrush brush = new SolidBrush(thisColor);
	g.FillRectangle(brush, 0, 0, 10, 10);
}
When I debug and look at the values:
cmykColor has Cyan=255, Magenta=0, Yellow=0, Black=0, Alpha=255
thisColor has Red=255, Green=0, Blue=0, Alpha=255

And then I end up with a 10x10 bitmap that is red and not cyan

Re: Correctly convert from ColorCMYK to MagickColor

Posted: 2019-03-24T01:08:15-07:00
by dlemstra
Thanks for reporting this! The problem is this statement:

Code: Select all

SolidBrush brush = new SolidBrush(thisColor);
This will convert the MagickColor to a System.Drawing.Color but it does not convert the CMYK color to RGB. I just pushed a patch to resolve this in Magick.NET and I will try to publish a new release later today that includes this fix.

Re: Correctly convert from ColorCMYK to MagickColor

Posted: 2019-03-25T06:24:47-07:00
by rondo
Thanks! I will check it out soon!