We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am trying to copy my main Processing output to an off screen buffer (to later send out to some LEDs).
I feel like I'm close but I'm not getting any results.
I have simplified my code and commented the lines that I'm having trouble with.
int y= 1;
PImage tempBuffer;
PGraphics offScreenBuffer;
void setup() {
size(1280,720);
offScreenBuffer = createGraphics(16, 9);
stroke(255);
}
void draw() {
background (0);
offScreenBuffer.beginDraw();
fill (255,0,0,255);
rect (0,y,1280,80);
y=(y+2) % 720;
loadPixels();
tempBuffer = get(0,0,1280,720); // copy screen to temp buffer
offScreenBuffer.image(tempBuffer, 0, 0,16,9); // copy temp to offscreen and scale to 16x9
offScreenBuffer.copy(0,0,16,9,0,0,160,90); // copy back to the top corner for debug
offScreenBuffer.endDraw();
noFill();
rect(0,0,160,90); // stroke for debug
}
Answers
I don't think it's a good idea read/write pixels until after endDraw(). L-)
Thanks, I just added an endDraw() to my offscreen buffer and it still didn't work.
I'm wondering if my methodology is right as currently my code runs really slow, possibly because I am copying from draw() to temp then temp to offScreen.
Is there a way to go directly from my 1280x720 draw() to my 16x9 offscreen?
Thanks.
Phil
`
We can always use image() w/ 5 arguments for resized display:
https://processing.org/reference/image_.html
Your copy() function is a better option. However, pass getGraphics() as the 1st source argument, so you save the extra get():
https://Processing.org/reference/PImage_copy_.html
hmmm.
I feel like I'm close, I simplified my code and it does run much faster (thanks)
But I am still not seeing the copy in the top left.
Below is my simplified code.
Any ideas?
Thanks
Phil
This works perfectly thanks so much.
I presume I can use
led.loadPixels();
and
led.get(x, y);
in the rest of my code and if I don't want to display the buffer I remove the.
set(0, 0, led);
Thanks again, this is perfect.
Phil
Neither get() needs loadPixels() before, nor set() needs updatePixels() after in Processing (except p5.js).
loadPixels() is used before reading from pixels[]. updatePixels() is used after finished writing to pixels[].
Hi, I am SURE that this code used to work but I just reopened my sketch and it's giving me an error in Processing 2.21 and Processing3.
The line that failed is the line copying one buffer to another.
The error I get is
the method copy (Pimage, int, int, int, int, int, int, int) in the type Pimage is not applicable for the arguments (Graphics,int, int, int, int, int, int, int)
It seems like copy function doesn't like using getGraphics().
I just tried the example sketch from @GoToLoop above and get the same error.
Any ideas?
Thanks Phil
The example I've posted here for you almost 1 year ago is still working under Processing 3.1.2 for me. :-@
Weird, I just tried again on the most recent version (3.23) and still get an error.
Here is my screenshot, maybe you can see something obvious.
Thanks,
Phil
https://GitHub.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L1280-#L1282
https://Processing.org/reference/PGraphics.html
http://docs.Oracle.com/javase/8/docs/api/java/awt/Component.html#getGraphics--
http://docs.Oracle.com/javase/8/docs/api/java/awt/Graphics.html
https://GitHub.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L183-#L184
Thanks @GoToLoop weird about the version. I have multiple versions installed and thought I had launched v3.
The g parameter works PERFECTLY.
Thanks
Phil