如何使用 .NET 4 中的 CMYK ColorSpace 将文本添加到图像

发布于 2024-10-07 06:18:01 字数 1401 浏览 0 评论 0原文

我正在开发一个项目,其核心涉及向图像添加文本,因此作为一个示例,给定背景图像 (B) 和指定字体、点大小和字体 (A) 中的一些文本,将两者合成在一起以生成(三): Example Image

最终结果是使用这些图像进行打印,因此背景使用 CMYK 色彩空间,我需要使整个过程保持在 CMYK 范围内,否则打印时颜色看起来不正确。 (注: CodeProject 上关于色彩空间和 .NET 的优秀文章

我尝试了几种不同的方法将这些图像合成在一起:

  • System.Drawing 隐式地将所有内容转换为 RGB
  • System.Windows.Media.Imaging - 没有合成方法
  • System.XAML/WPF - 非常有希望,但是 RenderTargetBitmap 不适用于PixelFormats.Cmyk32(引发 ArgumentException)。

我看过但没有尝试过第三方商业组件,因为价格似乎开始很高并且继续上涨:

这在 .NET 4 中可能吗?

编辑: 因为其他人可能想做一些稍微不同的事情,只是将 Windows.System.Media.Imaging 能够加载的任何格式转换为 CMYK,这里是我使用的代码:

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

为了澄清上面的代码转换CMYK32 的图像源(无透明度),但是如果您使用某些类(即 RenderTargetBitmap 传递上述 ImageSource 将引发异常)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同尘 2024-10-14 06:18:01

如果您经常查看 SO,您可能已经看到了这些链接。但是,为了以防万一,这里有一些我发现可能对您有帮助的链接。

以下是关于在 .NET 中使用 CMYK 的链接:

Convert RGB color to CMYK?

具体来说,它提到使用颜色配置文件和 Windows 颜色管理API。

这是另一个 SO 链接:

如何在 indesign 中以编程方式将 CMYK 转换为 RGB

一位回答者提到 CMYK 和 RGB 之间没有精确的转换。

以下是有关合成两个 CMYK 图像而不转换为 RGB 的链接:

任何 CMYK 图形库?

回答者建议使用他所属的商业产品。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文