Creating PDF when using copy() and multiple images
in
Core Library Questions
•
5 months ago
Hi,
I've written a sketch that imports two photos and then uses the copy() and updatePixels() commands to sample parts of one picture and insert them into the other. The core of the program runs fine, except that I am having trouble getting it to generate a pdf image using the Processing.pdf library. It generates an error message saying "No copy() for PGraphicsPDF."
Does anyone know a way to make this work? I'm wondering if the issue is that PDF's need flattened images. If that's the case, is there a way to flatten multilayered images in Processing like the Flatten function in Photoshop? Or is there a better way to import the images into the sketch that would be more compatible with Processing.pdf? Or is there a way to delete an image from the sketch once you've sampled it, so that there's only one layer left? (Or is the problem is something else entirely?)
Here's the code. Advice would be most appreciated.
~
import processing.pdf.*;
void setup() {
size (800, 800);
smooth();
beginRecord (PDF, "filename.pdf");
}
void draw() {
//loads two images into the sketch
PImage myImage = loadImage ("Picture1.jpg");
image (myImage, 0, 0);
PImage myImage2 = loadImage ("Picture2.jpg");
image (myImage2, 0, 0);
pushMatrix();
loadPixels(); //samples the pixels
//defines parameters for pixel sampling
int w = int(random(width));
for (int i = 0; i < 300; i++) {
int x = int(random(50,100));
int y = int(random(height));
//moves the pixels around
copy (myImage2, w, y, x, x, int(random(-100,900)), y, x, x);
}
updatePixels(); //writes the new arrangement of pixels
popMatrix();
endRecord();
noLoop();
}
1