Pardon my noobness, but how to I read the widht and height of images?

I am loading images and would like to store the width and height of them in the setup. How do I do that?


Hi @pepeu, you can get the width or height of an image anytime by calling the functions .getWidth() or .getHeight() on an ofImage. These functions return a floating point number, which can be stored in a float variable like this:

float imageWidth = image.getWidth();
float imageHeight = image.getHeight();

If you’re just learning openFrameworks (OF) and how to write c++ code, there are some things on the OF website that can help. Have a look at ofBook, which covers a lot of the things that OF can do:

And be sure and check out the Learning tab of the OF website (ofBook is there too).

Also, there are a lot of projects in the /examples folder that comes with OF. The graphicsExample, polygonExample, and colorExample are some fun ones to explore in the /examples/graphics/ folder.

1 Like

Aah, thank you! So simple. Haha! Cheers!

1 Like