3

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).

Richard Slater
  • 6,313
  • 4
  • 53
  • 81

1 Answers1

1

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.

Community
  • 1
  • 1
wageoghe
  • 27,390
  • 13
  • 88
  • 116
  • Thanks for posting those up, I have looked around and found some resources for converting bitmap formats using .NET (posted a code sample in my question for googlers), it is key to the quality of the printed images for the source images to be kept in CMYK format. – Richard Slater Dec 14 '10 at 09:24
  • I have had a look at Atlasoft DotImage, the "Pro" version seems to do what I want to do, however it costs about US$3000. – Richard Slater Dec 14 '10 at 09:37
  • Be aware that converting from-to RGB/CMYK isn't reversible - you'll lose some color information. – Daniel Mošmondor Dec 14 '10 at 09:52
  • Indeed, the very reason that I avoiding taking our existing source images and converting them to RGB at the intermediate step. – Richard Slater Dec 14 '10 at 09:54
  • I have ended up using a PDF (iTextSharp) library to composite text over images, as this retains the font glyphs and CMYK images. The font's are still specified in RGB however the colours are simple enough not to be an issue. – Richard Slater Dec 24 '10 at 11:33