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):
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:
- Graphics Mill (~US$1800 as of 12/2010)
- Atalasoft DotImage (~US$3300 as of 12/2010)
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).