Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
vvdboogaard
vvdboogaard's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Print current sketch
[0 Replies]
26-May-2011 05:57 AM
Forum:
Programming Questions
Hi all,
I just made a sketch which I want to print. I'm puzzeling with Java's Print but I can't get it right..
Class:
public class HelloWorldPrinter implements Printable {
public int print(Graphics g, PageFormat pf, int page) throws
PrinterException {
if (page > 0) { /* We have only one page, and 'page' is zero-based */
return NO_SUCH_PAGE;
}
/* User (0,0) is typically outside the imageable area, so we must
* translate by the X and Y values in the PageFormat to avoid clipping
*/
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
/* Now we perform our rendering */
// g.drawString("Hello world!", 100, 100);
// g.drawString(day() + " " + month(), 100, 120);
frame.printAll(g);
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
}
Sketch:
import java.io.File;
import java.awt.print.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
PImage[] IMGs;
int minWidth = -1;
ArrayList parts;
void setup(){
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new HelloWorldPrinter());
PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
parts = new ArrayList();
***** CODE *****
println("Partssize: " + parts.size());
for(int i = 0; i < parts.size(); i++){
IMG part = (IMG) parts.get(i);
image(part.img, 0, i, width, 1);
}
saveFrame();
try {
println("Trying to print..");
job.print();
println("Printed");
}
catch (PrinterException e) {
/* The job did not successfully complete */
println("Error:");
println(e);
}
}
(IMG is a class where I can store information about an image layer)
Can someone explain to me what I'm doing wrong? I allready found that Java Print uses Graphic2D but I can't manage to convert the sketch to Graphic2D..
«Prev
Next »
Moderate user : vvdboogaard
Forum