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 »

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: 25562
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 »

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 »

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: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Correctly convert from ColorCMYK to MagickColor

Post 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.
.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 »

Thanks! I will check it out soon!
Post Reply