Centered image in setup(); !?

Hi all.

Is there any way to centered image in setup(); after img.loadImage(…); ?
I don’t want to draw the image ,I just want to load in setup() method and the image to be loaded in center of window not in left upper side of window.
How can I do this ?

Thank you.

The image will only appear when you draw() it

Something like this should put it in the centre, assuming the image is smaller than the window.

int x_pos = (ofGetWidth() - img.getWidth())/2.0;
int y_pos = (ofGetHeight() - img.getHeight())/2.0;
img.draw(x_pos, y_pos);

Hey @pants thanks for reply. I don’t want to draw the image, I just want to load and to set the image position in center of window on setup() method.

hey np, i dont think I quite understand what you are asking about


An ofImage has no position.
When you draw it, you must provide the position. The first pants answer show how to do.
If you don’t draw it, position is meaningless.

You can’t do something like:

myImage.x = 100;  
myImage.y = 50;  

and later:


This doesn’t work. OF don’t work like Actionscript (flash) display objects, for example, where each display object have position properties x and y.

Instead you must do:

myImage.draw(100, 50);