A practical example:
- import processing.pdf.*;
- PImage myImage;
- PImage myImage2;
- void setup() {
- size (800, 800);
- smooth();
- myImage = loadImage ("H:/Temp/Tree.jpg"); // I just use absolute paths because I don't save these small test sketches... So no data folder for me!
- myImage2 = loadImage ("H:/Temp/Test.jpg");
- beginRecord (PDF, "H:/Temp/filename.pdf");
- }
- void draw() {
- PGraphics result = createGraphics(width, height, JAVA2D);
- result.beginDraw();
- result.image (myImage2, 0, 0);
- int w = int(random(width));
- for (int i = 0; i < 300; i++) {
- int x = int(random(50, 100));
- int y = int(random(height));
- result.copy (myImage, w, y, x, x, int(random(-200, 1200)), y, x, x);
- // endRecord(); // Should be after the loop, if you use this style
- }
- result.endDraw();
- image(result, 0, 0);
- endRecord();
- println("Done");
- noLoop();
- exit();
- }