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.
Page Index Toggle Pages: 1
PImage resize() (Read 780 times)
PImage resize()
Apr 28th, 2010, 12:51am
 
Why does the following code create 2 images of the same size? I would expect it to make one image width 100 and one image width 200!

////////////////////////////////////
PImage one;
PImage two;

void setup(){


 size(400,400);


 one = loadImage("squibles.jpg");

 two=one;

 one.resize(100,0);
 two.resize(200,0);

 image(two,0,0);
 image(one,200,200);
}
Re: PImage resize()
Reply #1 - Apr 28th, 2010, 12:59am
 
two = one;
You don't copy the image (use get() for that), you make two to have the same reference as one.
So the two resize() calls act on the same image.
Re: PImage resize()
Reply #2 - Apr 28th, 2010, 1:04am
 
I raced back here after I checked the docks, I should know better.

How come when you smo.clone() it throws the java.lang.CloneNotSupportedException ?

Why does
 two=(PImage)one.clone();
not work?
Re: PImage resize()
Reply #3 - Apr 28th, 2010, 1:23am
 
Are you sure it throws this exception (when running)
Or you have a compilation error telling you must catch this exception
clone() JavaDoc:
Quote:
Duplicate an image, [...]. This is implemented as an override of Object.clone(). We recommend using get() instead, because it prevents you from needing to catch the CloneNotSupportedException, and from doing a cast from the result.

get() just calls clone() with proper incantations...
Re: PImage resize()
Reply #4 - Apr 28th, 2010, 2:15am
 
It indeed tells me I have to catch the exception. I need to be more careful with my wording.

O get..... Yeah I should have done that the whole time and managed to miss that.

If you check the references for get()

http://processing.org/reference/PImage_get_.html is not among them you have to look under PImage specifically. Thats a bit confusing but it is still my fault for hastily reading through the docs  Undecided

Thank you for your reply.

Page Index Toggle Pages: 1