Filter 如何使用Ghostscript在Postscript中导入png文件?

Filter 如何使用Ghostscript在Postscript中导入png文件?,filter,png,ghostscript,postscript,Filter,Png,Ghostscript,Postscript,我正在尝试将png图像放置在postscript文档上,以便使用Ghostscript(V9.15)ps2pdf将其转换为pdf文件。我发现以下代码可以很好地处理jpg文件,但我需要导入png文件。看起来我需要一个不同的过滤器,但我找不到一个有效的。有人有解决办法吗 239 % number of pixels in the horizontal axis 67 % number of pixels in the

我正在尝试将png图像放置在postscript文档上,以便使用Ghostscript(V9.15)ps2pdf将其转换为pdf文件。我发现以下代码可以很好地处理jpg文件,但我需要导入png文件。看起来我需要一个不同的过滤器,但我找不到一个有效的。有人有解决办法吗

239                     % number of pixels in the horizontal axis
67                      % number of pixels in the vertical axis
8                       % bits per color channel (1, 2, 4, or 8)
[239 0 0 -67 0 67]      % transform array... maps unit square to pixel [ w 0 0 -h 0 h ]
(My_Logo.jpg) (r) file  % see page 587 and page 77 for more details
/DCTDecode filter       % see page  589
false                   % pull channels from separate sources
3                       % 3 color channels (RGB)
colorimage              % see page 544 and page 288 for more detail

PostScript不直接支持PNG,它支持JPEG,这就是上面代码工作的原因

如果要从PNG文件中读取图像数据,需要打开该文件,去掉标题,然后逐个读取每个块,并解析其中的数据。将位图数据写入中间文件可能是最容易的,但完全可以编写流解码器来提供程序图像数据源所需的数据

幸运的是,PostScript(级别3,当然是级别2的大多数版本)确实支持Flate,因此您不必在PostScript中编写解压缩代码,您可以直接使用过滤器

根据PNG是否使用调色板,您需要指定颜色空间

PostScript是一种编程语言,所以这一切都是可能的,我认为编写和调试它需要一个有经验的PostScript程序员几天的时间


注意!PostScript不支持透明度,因此您根本无法从PNG文件应用alpha通道。

Bummer。因此,下一个最好的解决方案是将png文件转换为jpg文件,然后像上面那样导入,对吗?JPEG是一种有损压缩方法,您可能最好将其导出为原始位图或其他同样简单的格式,并使用该格式。PPM是一种记录良好的“原始”格式,可以工作。不过,它可以生成大文件,因为根本没有压缩。而且你还需要剥去收割台。