我知道如何使用postcript轉換/寫一個BufferedImage到後記
我現在正在尋找如何繪製內容BufferedImage(寬*高)的PostScript頁面得出一些簡單的形狀(X,Y ,寬度,高度)沒有任何外部庫(FOP,PDFBox ...)。
你有任何提示/代碼/算法?
謝謝! :-)
我知道如何使用postcript轉換/寫一個BufferedImage到後記
我現在正在尋找如何繪製內容BufferedImage(寬*高)的PostScript頁面得出一些簡單的形狀(X,Y ,寬度,高度)沒有任何外部庫(FOP,PDFBox ...)。
你有任何提示/代碼/算法?
謝謝! :-)
必須使用image
或colorimage
運算符。 與簡單的內聯繪製和show
文本運算符不同,這些是複雜的運算符 ,它們需要幾個參數。
我正在把一個示例postscript片段呈現一個8×8圖像使用 7參數colorimage
運算符。請注意,第5個參數實際上是一個回調過程,可能會由colorimage操作符多次調用,每次都會返回一些字符串中的圖像數據。在這個例子中,我一次返回整個圖像數據。 在這個例子中,這個數據是ASCII編碼的,每個字節被表示爲2位十六進制數字。更高效的編碼是可能的,因爲Postscript可以在運行時解碼base64,base85和RLE編碼。
此參數可能是單個字符串而不是回調過程,但在這種情況下, 二進制數據必須以八進制數字進行轉義,前面的斜槓(如\ 377)爲十進制255。與currentfile
讀取操作符是相當通常 表示Postscript圖像。
注意,圖像通常映射到在renderign空間(0,0,1,1)的正方形,並 一個具有設置全局變換矩陣(與translate
,scale
,rotate
運營商)之前渲染圖像。
完整image
和colorimage
參考可以在PostScript語言Refrence由Adobe提供http://www.adobe.com/products/postscript/pdfs/PLRM.pdf
中找到另一個例子,嘗試運行GIMP
程序,並從內部將其保存的圖像作爲後記。
%!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