We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › copy applet graphics screen, how
Page Index Toggle Pages: 1
copy applet graphics screen, how? (Read 1236 times)
copy applet graphics screen, how?
Oct 16th, 2005, 9:06pm
 
I want to copy the drawing on the applet to a PImage buffer. Copy() doesn't seem to work.
Code:

loadPixels();
updatePixels();
buffer.loadPixels();
buffer.copy(0, 0, width, height, 0, 0, buffer.width, buffer.height);
buffer.loadPixels();
buffer.updatePixels();

Evidently loadPixels() and updatePixels don't make a difference.
Re: copy applet graphics screen, how?
Reply #1 - Oct 17th, 2005, 12:04am
 

does buffer.copy (g, 0,0, width, height, 0,0, b.width, b,height); syntax make any difference?
Re: copy applet graphics screen, how?
Reply #2 - Oct 17th, 2005, 9:06am
 
Code:

PImage buffer;
int w = 200, h = 200;
void setup()
{
size(400,200);
background(0);
buffer = new PImage(w,h);
}

void draw()
{
if(mousePressed){
buffer = getScreen();
image(invert(buffer),w,0);
}
else
{
stroke(255);
point(random(w),random(h));
}
}

void mouseReleased()
{
background(0);
}

PImage getScreen()
{
PImage ret = new PImage(width,height);
loadPixels();
for(int i = 0; i < pixels.length; i++)
ret.pixels[i] = pixels[i];
return ret;
}

PImage invert(PImage img)
{
PImage ret = new PImage(width,height);
for(int i = 0; i < img.pixels.length; i++)
ret.pixels[i] = color(255-red(img.pixels[i]),255-green(img.pixels[i]),255-blue(img.pixels[i]));
return ret;
}


this makes a screencopy at least.. (and inverts it) .. and it works not using copy()..

And loadPixels() are for loading pixels on screen to pixels[], and updatePixels() are for when you've changed stuff in pixels[].


-seltar
Re: copy applet graphics screen, how?
Reply #3 - Oct 17th, 2005, 5:35pm
 
to do a copy, you need only do this:

PImage screen = get();

which will give you a PImage that's direct from the screen and can be played with.

this doesn't work because it's just copying the image into itself:
buffer.copy(0, 0, width, height, 0, 0, buffer.width, buffer.height);

the function is
copy(int sx1, int sy1, int sx2, int sy2, int dx1, int dy1, int dx2, int dy2);
where the coordinates are "s" is for source, and "d" is for destination.

if you're using imageMode(CORNER) then it will be:
copy(int sx, sy, sw, sh, dx, dy, dw, dh);
where sw/sh are the source width/height (and same for d).

in your case you'd use this guy:
public void copy(PImage src, int sx1, int sy1, int sx2, int sy2, int dx1, int dy1, int dx2, int dy2)

so you'd say something like:
buffer.copy(g, 0, 0, width, height, 0, 0, buffer.width, buffer.height);
Re: copy applet graphics screen, how?
Reply #4 - Oct 18th, 2005, 2:16pm
 
This command throws a null pointer exception:

buffer.copy(g, 0, 0, width, height, 0, 0, buffer.width, buffer.height);

example:
Code:

PImage buffer;
void setup(){
size(200,200);
buffer = loadImage("blank40x40.gif");
}
void draw(){
buffer.copy(g, 0, 0, width, height, 0, 0, buffer.width, buffer.height);
image(buffer,0,0);
}
void mousePressed(){
fill(255,0,255);
rect(mouseX,mouseY,40,40);
}

If you replace the copy command above with buffer = get();, nothing happens. If I use PImage g = get();, nothing happens.

I need a compacted image so copying the pixels won't work.
Re: copy applet graphics screen, how?
Reply #5 - Oct 19th, 2005, 1:24pm
 
AAAAAARRRRGGGHHH!

Why do I have to figure these things out myself?
Code:

PImage buffer;
void setup(){
size(200,200);
buffer = new PImage(40,40);
}
void draw(){
loadPixels();
buffer.copy(g, 0, 0, width, height, 0, 0, buffer.width, buffer.height);
buffer.updatePixels();
image(buffer,0,0);
}
void mousePressed(){
fill(255,0,255);
rect(mouseX,mouseY,40,40);
}

That is why I was trying to use loadPixels(). I figured that logically copy() must make use of pixels[].
Re: copy applet graphics screen, how?
Reply #6 - Oct 19th, 2005, 5:39pm
 
st33d wrote on Oct 19th, 2005, 1:24pm:
Why do I have to figure these things out myself

because you're using software that 1) is still beta 2) was downloaded for free 3) is written by one guy and documented by another who both have full time jobs doing something other than processing.

take it easy, chief.
Re: copy applet graphics screen, how?
Reply #7 - Oct 19th, 2005, 7:40pm
 
I've learned about "g" and how to make a blank PImage using buffer = new PImage(width,height).

I've also learned everything I know about programming and math by using this forum. I gain only conceptual support from my tutors and get help mostly with equipment from technical demonstrators. The computing course at the university is off-site.

Chief is easy. Chief was just a little fustrated that the answers to my question were not mind-reader precise. For that I apologise.

Chief also had an almighty hangover from the Chapman Brothers private view. Some god-like quantity of drinking took place last night. I remember scaling a tall fence with a carrier bag full of chicken and chips and accusing my tutor of looking like Meatloaf. He called me a ****.

I may not sound grateful but I basically owe this website for my distinction last year. Cheers.
Page Index Toggle Pages: 1