Question

I am working on a project that at it's core involves adding text to an image, so as an example given a background image (B) and some text in a specified font, point size and font (A) the two are composited together to produce (C): Example Image

The eventual result is to go to print with these images, so the backgrounds are using the CMYK Color Space and I need to keep the whole process within CMYK or the colors look wrong when printed. (note: excellent article on Color Spaces and .NET on CodeProject)

I have tried several different ways of compositing these images together:

  • System.Drawing implicitly converts everything to RGB
  • System.Windows.Media.Imaging - no compositing methods
  • System.XAML/WPF - very promising however RenderTargetBitmap does not work in PixelFormats.Cmyk32 (throws an ArgumentException).

I have looked at but not tried third party commercial components as the prices seem to start high and continue going up:

Is this possible in .NET 4?

Edit: Because someone else might want to do something slightly different and just convert any format that Windows.System.Media.Imaging is able to load to CMYK here is the code I have used:

var bitmapConverter = new FormatConvertedBitmap();
bitmapConverter.BeginInit();
bitmapConverter.Source = sourceImage;
bitmapConverter.DestinationFormat = PixelFormats.Cmyk32;
bitmapConverter.EndInit();

To clarify the above code converts an image source to CMYK32 (no transparency) however if you are using certain classes (namely RenderTargetBitmap passing the above ImageSource will throw an exception).

Was it helpful?

Solution

If you have looked much on SO, you have probably already seen these links. But, just in case, here are some links that I found that might be helpful to you.

Here is a link from here on SO about working with CMYK in .NET:

Convert RGB color to CMYK?

Specifically it mentions using Color Profiles and Windows Color Management APIs.

Here is another SO link:

How to convert CMYK to RGB programmatically in indesign

One answerer mentions that there is not an exact conversion between CMYK and RGB.

Here is a link about compositing two CMYK images without converting to RGB:

The are any CMYK graphics library?

The answerer suggests using a commercial product that he is affiliated with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top