Correctly convert from ColorCMYK to MagickColor

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
rondo
Posts: 8
Joined: 2018-11-15T13:47:59-07:00
Authentication code: 1152

Correctly convert from ColorCMYK to MagickColor

Post by rondo » 2019-03-20T13:13:09-07:00

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.

User avatar
fmw42
Posts: 25423
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Correctly convert from ColorCMYK to MagickColor

Post by fmw42 » 2019-03-20T16:21:15-07:00

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.

rondo
Posts: 8
Joined: 2018-11-15T13:47:59-07:00
Authentication code: 1152

Re: Correctly convert from ColorCMYK to MagickColor

Post by rondo » 2019-03-21T06:45:27-07:00

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

User avatar
dlemstra
Posts: 1567
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Correctly convert from ColorCMYK to MagickColor

Post by dlemstra » 2019-03-24T01:08:15-07:00

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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

rondo
Posts: 8
Joined: 2018-11-15T13:47:59-07:00
Authentication code: 1152

Re: Correctly convert from ColorCMYK to MagickColor

Post by rondo » 2019-03-25T06:24:47-07:00

Thanks! I will check it out soon!

Post Reply