Search code examples
.netimagemagickimagemagick-convert

MagickImage create same color irrespective of colorspace


I am trying to set the border color for any image from any colorspace to white. Right now I am doing something like,

if (image.ColorSpace == ColorSpace.CMYK)
  image.BorderColor = new MagickColor(0, 0, 0, 0, 0); // Set border color as white (CMYK)
else
  image.BorderColor = new MagickColor("#FFFFFF"); // Set border color as white (RGB)

but this doesn't seem to be comprehensive, because in this case we need to look at other color spaces and see that they also fit into this.

I faced a problem where one image had colorspace as Lab, there the above code produces red borders. So I am looking for a simple way of doing this.

Any help on this would be greatly appreciated.


Solution

  • Thanks to @emcconville, I was able to get a simpler solution for this.

    The MagickColor class accepts X11 color names as parameters, so we can achieve the same using

    image.BorderColor = new MagickColor("WHITE");
    

    This sets the border color as white irrespective of the ColorSpace.

    For those of you wondering what X11 color names are, https://en.wikipedia.org/wiki/X11_color_names.