将BufferedImage转换/写入postscript [英] Converting/writing a BufferedImage to postscript

查看:127
本文介绍了将BufferedImage转换/写入postscript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用后记

我现在正在寻找如何绘制内容 BufferedImage (width * height)到postscript页面(x,y,width,height)没有任何外部库(FOP,PDFBox ...)。

I'm now looking how to draw the content BufferedImage(width*height) to a postscript page (x,y,width,height) without any external library (FOP,PDFBox...).

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

Do you have any hint/code/algorithm ?

谢谢! : - )

推荐答案

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

One has to use the image or colorimage operators. Unlike the simple linedrawing and showtext operator, these are complex operators that take several parameters.

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

I am putting a sample postscript snippet which renders an 8 x 8 image using the 7 parameter colorimage operator. Take notice that the 5th parameter is actually a callback procedure, that may be called several times by the colorimage operator, each time returning some of the image data in a string. In this example, I return the whole image data at once. In this example, this data is ASCII encoded with each byte being represented as 2-digit hexadecimal number. More efficient encodings are possible, as Postscript can decode base64, base85 and RLE encoding in runtime.

此参数可能是单个字符串而不是回调过程,但在此case,
二进制数据必须以八进制转义,前面的斜杠(如\ 377)表示十进制255.使用用 currentfile 运算符通常是
来表示Postscript图像。

This parameter might be a single string instead of a callback procedure, but in this case, binary data would have to be escaped in octal, with a preceding slash (like \377) for decimal 255. Using inline data that is read with the currentfile operator is rather usual for representing Postscript images.

请注意,图像通常映射到渲染空间上的(0,0,1,1)方格,而
必须设置全局转换矩阵( translate scale rotate 运算符在渲染图像之前。

Note that the image is usually mapped to the (0,0,1,1) square on the renderign space, and one has to set the global transformation matrix (with the translate, scale, rotate operators) prior to rendering the image.

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

The complete image and colorimage reference can be found on the Postscript Language Refrence by Adobe available at http://www.adobe.com/products/postscript/pdfs/PLRM.pdf

再举一个例子,试试运行 GIMP 编程并将图像保存为Postscript。

For another example, try running the GIMP program and saving an image as Postscript from within it.

%!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

这篇关于将BufferedImage转换/写入postscript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆