【问题标题】:Create CMYK+alpha bitmap, mapping black to specific CMYK color创建 CMYK+alpha 位图,将黑色映射到特定的 CMYK 颜色
【发布时间】:2015-12-10 17:54:42
【问题描述】:

鉴于此拱形文本图像,透明背景上的黑色像素,抗锯齿

我最终希望对此文本进行 CMYK 渲染,其中每个黑色像素都变成特定的 CMYK 颜色,例如洋红色或 {72,36,9,28},或者我的客户指定的任何颜色。最终输出将是 PDF。每个透明像素都需要保持透明,因为文本下可能还有其他 PDF 对象。

我会满足于将 CMYK+Alpha TIFF 等效写入磁盘。或者,可能是 System.Windows.Media.Imaging.Bitmapimage。或者别的什么。

我的 PDF 库是 ABCpdf.NET 10。我意识到 System.Drawing 不支持 CMYK 颜色格式。我对其他第三方库没意见;我已经在库中的另一个上下文中使用 AForge。

希望进行 RGB 到 CMYK 的转换,甚至没有配置文件。我希望在 PDF 中进行通用颜色替换。我的客户会指定一个明确的 CMYK 目标颜色,我需要完全匹配它;在 RGB 近似值上使用颜色转换是不行的。

我一直在玩各种各样的事情。我得到的最接近的是在保持 RGB 的同时交换颜色——黑色变为透明,透明变为白色——并在图像下方绘制一个填充的洋红色框。然后在没有文本的地方绘制白色像素,并且下面的洋红色显示出来。考虑作为一个组,这最终看起来像白色上扭曲的洋红色文本。但是任何坐在该组下面的东西都不会显示出来。 link

有什么想法吗?

【问题讨论】:

    标签: .net pdf colors bitmap abcpdf


    【解决方案1】:

    websupergoo 的 Jos Vernon 提出了一个非常简单的答案,它使用了 ABCpdf 功能。

    using WebSupergoo.ABCpdf10;
    using WebSupergoo.ABCpdf10.Objects;
    
    namespace RecolorRenderedImage
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (Doc theDoc = new Doc()) {
                    // this background image is there to prove that the text is not obscuring other pdf objects
                    theDoc.AddImage("c:\\temp\\background-pic.jpg");
    
                    // this is the black warped text
                    string fullFilePath = "c:\\temp\\foobar.png";
    
                    // read it into an XImage. Add to the doc, and retrieve the pixmap
                    XReadOptions readOptions = new XReadOptions();
                    XImage image = XImage.FromFile(fullFilePath, readOptions);
                    int theID = theDoc.AddImageObject(image, true);
                    int imageID = theDoc.GetInfoInt(theID, "XObject");
                    PixMap thePM = (PixMap)theDoc.ObjectSoup[imageID];
    
                    // recolor the pixmap temporary spot color space with the desired color (gold in this case)
                    int spotColorID = theDoc.AddColorSpaceSpot("tempSpace", "24 44 100 2");
                    ColorSpace theSP = (ColorSpace)theDoc.ObjectSoup[spotColorID];
                    thePM.Recolor(theSP);
    
                    // immediately recolor the pixmap back to CMYK
                    ColorSpace theSP2 = new ColorSpace(theDoc.ObjectSoup, ColorSpaceType.DeviceCMYK);
                    thePM.Recolor(theSP2);
    
                    theDoc.Save("c:\\temp\\test.pdf");
                }
            }
    
        }
    }
    

    后期编辑:删除了指向输出文件的链接,因为我在某个时候从 GDrive 中删除了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 2013-01-28
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多