프로세싱이 1.0.5 버전까지 업데이트 되면서 베타 버전에서는 꿈꿀수 없는 많은 부분이 가능해졌다.
(개인적으로 3D 에서 smooth() 가 적용되는 것이 최고.^-^)
하지만 여전히 프린터로 출력 하는 함수가 없는 관계로 자바에서 그부분을 프로그램 해서 사용해야만 한다.
본인도 프로그램을 잘 하지 못하는 관계로 http://processing.org 에서 print out 이라는 검색어로 검색한 결과
pitaru 가 올려 놓은 글에서 printer_out 소스(첨부파일 참고)를 얻을수 있었다.
printer_output.pde
/*
This code Prints the stage into the defaule printer device.
It was tested on a PC Windows XP machine, using ***Processing version 91***
(V92 may lock up the application on some machines)
Code adapted for Processing By Ben Fry and Amit Pitaru
on October 15th 2005
For a java good example on the Java Printing API, visit this link:
http://www.javacommerce.com/displaypage.jsp?name=printcode.sql&id=18252
Press 'p' to print out the stage non-threaded.
Press 't' to print out the stage as a seperate thread operation.
*/
import java.awt.print.*;
PImage img;
void setup() {
size(200,200);
img = loadImage("arch.jpg");
}
void draw() {
background(255);
image(img,0,0);
line(0, 0, 100, 100);
}
void keyPressed(){
// invoke the print routines as a seperate thread
if(key == 't') printStageThreaded();
// invoke th eprint routines without a thread
if(key =='p') printStage();
}
키보드에서 " t " 또는 " p " 키를 누르면 바로 프린트를 하게된다.
printRoutines.pde
PrinterJob job;
// called by the main code to start a new print job as a thread
void printStageThreaded(){
// Create an object that will hold all print parameters, such as
// page size, printer resolution. In addition, it manages the print
// process (job).
job = PrinterJob.getPrinterJob();
Runnable printRunner = new Runnable() {
public void run() {
handlePrint();
}
};
javax.swing.SwingUtilities.invokeLater(printRunner);
}
// called by the main code to start a new print job
void printStage(){
// Create an object that will hold all print parameters, such as
// page size, printer resolution. In addition, it manages the print
// process (job).
job = PrinterJob.getPrinterJob();
handlePrint();
}
// called by printThread to set the print job for the stage.
void handlePrint() {
job.setPrintable(new Printable() {
public int print (Graphics pg, PageFormat f, int pageIndex) {
switch (pageIndex)
{
case 0 :
pg.drawImage(g.image, 0, 0, null);
return Printable.PAGE_EXISTS;
default:
return NO_SUCH_PAGE; // No other pages left
}
}
}
);
try {
job.print();
}
catch (PrinterException e) {
System.out.println(e);
}
}
위의 소소를 이용해서 프린트시 용지에 맞는 프린트가 안된다거나 크기가 너무 크게 출력된다거나 하는 문제점들이 나타난다.
"printRoutines.pde" 파일은 프린트되는 출력물의 사이즈 및 옵션이 들어가 있다 그중에서
pg.drawImage(g.image, 0, 0, null);
pg.drawImage(g.image, 가로위치, 세로위치, null); 를 나타내며
pg.drawImage(g.image, 0, 0, 0, 0, null); 이렇게 사용되면
pg.drawImage(g.image, 가로위치, 세로위치, 가로사이즈, 세로사이즈, null); 를 나타낸다.
위의 빨간색와 녹색의 설명으로 본인이 필요로 하는 프린터 위치와 사이즈를 조절할수 있다.
Copyright © Smileblue.co.kr ( Jaejoong Lee ). All Right Reserved.
프로세싱 1.0.9 이하에서만 작동되는것 같네요 업데이트 이후 실행시 에러가 나네요..^^;; 1.0.9에서 익스포트 하세요~