 |
Author |
Topic: instantiating a BImage object (Read 362 times) |
|
kensuguro
|
instantiating a BImage object
« on: Nov 8th, 2004, 9:08am » |
|
BImage accepts width and height as initializing numbers, I know that. But I'm having trouble using variables instead of numbers. Is this not possible? I get no output as of now. here's what I want to do in a nutshell (nevermind the newFrame parts) Code: int tinyx; int tinyy; boolean newFrame = false; void setup() { size(320*3, 240); tinyx = 120; tinyy = 80; beginVideo(320, 240, 999); framerate(30); } /*--------------------- Images*/ BImage tinyvideo = new BImage(tinyx, tinyy); /*--------------------- Images*/ void videoEvent() { newFrame = true; } void loop() { if(newFrame == true) { tinyvideo.replicate(video, 0, 0, 320, 240, 0, 0, tinyx, tinyy); image(tinyvideo, 0, 0); } } |
|
|
|
|
|
TomC
|
Re: instantiating a BImage object
« Reply #1 on: Nov 8th, 2004, 12:26pm » |
|
Everything you initialise outside of a function will be initialised before setup runs. So at the time you initialise tinyvideo, tinyx and tinyy will both be uninitialised (and so, by default, zero). Treat tinyvideo like you did tinyx and tinyy. Declare it outside of setup, but initialise it in setup after you initialise tinyx and tinyy. Otherwise, your code should work, although you'll want to set newframe to false after you draw the image, and you might want to investigate replicating the image directly rather than via tinyvideo, or just drawing the video image at a different size using image(x,y,width,height).
|
|
|
|
kensuguro
|
Re: instantiating a BImage object
« Reply #2 on: Nov 9th, 2004, 6:10am » |
|
problem is, how would I initiate tinyvideo from within setup()? If I go (simplified code to illustrate the basic idea) Code: BImage tinyvideo = new BImage(); void setup() { tinyx = 120; tinyy = 80; tinyvideo(tinyx, tinyy); } |
| I get error that says "The name "tinyvideo" is not a method name but the name of a field member of type "Temporary_4824_9583"." Perhaps I'm doing this wrong by trying to use BImage's constructor after the time of instantiating. (constructors are only called upon instantiating right?) Is there a method I can use to initialize the size of a BImage? I see a width and height field, but they seem more of a way to retrieve the info, and not set them.. By the way, I'm trying to do the whole downscale thing becuase I'll be doing analysis on the downscaled images, and upscale the analysis to full res, and then apply effects in full res.
|
« Last Edit: Nov 9th, 2004, 7:06am by kensuguro » |
|
|
|
|
toxi
|
Re: instantiating a BImage object
« Reply #3 on: Nov 9th, 2004, 4:47pm » |
|
hi, to clear up your confusion a bit more: there's a difference between declaring and instantiating an object. you can do both things at once or separately. the latter is needed if you gonna use the object in a larger scope than the current method. so have a look at this corrected code: Code: int tinyx; int tinyy; boolean newFrame = false; BImage tinyvideo; // declare the variable + type void setup() { size(320*3, 240); tinyx = 120; tinyy = 80; // create the actual instance tinyvideo= new BImage(tinyx, tinyy); beginVideo(320, 240, 999); framerate(30); } void videoEvent() { newFrame = true; } void loop() { if(newFrame == true) { tinyvideo.replicate(video, 0, 0, 320, 240, 0, 0, tinyx, tinyy); image(tinyvideo, 0, 0); } } |
|
|
http://toxi.co.uk/
|
|
|
kensuguro
|
Re: instantiating a BImage object
« Reply #4 on: Nov 9th, 2004, 6:21pm » |
|
ah, okay. got it. thanx for going through the trouble.
|
|
|
|
|