将BufferedImage转换/写入postscript

时间:2011-02-07 18:12:03

标签: java image postscript

我知道如何使用 postcript

绘制一些简单的形状

我现在正在寻找如何将内容BufferedImage(宽度*高度)绘制到postscript页面(x,y,width,height)而不使用任何外部库(FOP,PDFBox ...)。 / p>

你有任何提示/代码/算法吗?

谢谢! : - )

1 个答案:

答案 0 :(得分:3)

必须使用imagecolorimage运算符。 与简单的有线和show文本运算符不同,这些是复杂的运算符 这需要几个参数。

我正在使用示例postscript片段,使用该片段呈现8 x 8图像 7参数colorimage运算符。请注意,第5个参数实际上是一个回调过程,可以由colorimage运算符多次调用,每次都返回字符串中的一些图像数据。在此示例中,我立即返回整个图像数据。 在此示例中,此数据是ASCII编码的,每个字节表示为2位十六进制数。更高效的编码是可能的,因为Postscript可以在运行时解码base64,base85和RLE编码。

此参数可能是单个字符串而不是回调过程,但在这种情况下, 二进制数据必须以八进制进行转义,前面的斜杠(如\ 377)表示十进制255.使用通过currentfile运算符读取的内联数据相当平常 用于表示Postscript图像。

请注意,图像通常映射到渲染空间上的(0,0,1,1)方格,并且 必须在渲染图像之前设置全局变换矩阵(使用translatescalerotate运算符)。

完整的imagecolorimage参考可以在Adobe的Postscript语言参考上找到http://www.adobe.com/products/postscript/pdfs/PLRM.pdf

另一个例子,尝试运行GIMP程序并将图像保存为Postscript。

%!PS-Adobe-3.0

% builds string to hold all image data at once:
/imgdata 8 8 3 mul mul string def

% set context to scale image to 256 X 256 pt (from 1 x1 pt)

256 256 scale

% Dimensions of image (width * height * bpp)

8 8 8

% Image transformation Matrix - [width 0 0 -height 0 height]: flips 
% vertical axis so we have top to bottom data:
[8 0 0 -8 0 8] 

% Procedure to read the image data and return it as a string:
{ currentfile % read inline data
  imgdata  % put read data into this variable
  readhexstring % performs the reading
  pop % discards read operation status
}

%indicates single data source:
false

%number of colors per pixel:
3
% Image operator: consumes previous parameters and renders the image
% followed by Image hexadecimal data in ASCII
colorimage 
0000000000200000400000600000800000a00000c00000e0200000200020
2000402000602000802000a02000c02000e0400000400020400040400060
4000804000a04000c04000e06000006000206000406000606000806000a0
6000c06000e08000008000208000408000608000808000a08000c08000e0
a00000a00020a00040a00060a00080a000a0a000c0a000e0c00000c00020
c00040c00060c00080c000a0c000c0c000e0e00000e00020e00040e00060
e00080e000a0e000c0e000e0

showpage