Width and height variable for ofImage are 'protected'

I’m going through some old code where I had loaded an ofImage and then used the width and height variable throughout the program, but now it doesn’t work.

I used to use backDrop.loadImage(), backDrop.width and backDrop.height

now I get: ‘width’ is a protected member of ‘ofImage < unsigned char >’

I know you can use getWidth(), but for referencing the with of an image it was kind of handy just to use ‘backDrop.width’. Is this a normal change in behaviour for how openFrameworks is supposed to work?

should the documentation on the ofImage page be changed so it doesn’t imply these variables should be accessible?

Yes, this is expected and “improved” behavior. Using the accessor methods rather than directly accessing the variables allows for better “encapsulation”, meaning that using the methods gives the developer better control over the internal state of the ofImage instance and also implementation details behind the scenes. Over the years, as more platforms have been supported, one implementation may not work on all platforms so there is generally a movement in openFrameworks to clean up, stabilize and make the API more consistent (i.e. you can call getWidth() on quite a few objects now). Additionally, you may notice that in recent versions of oF, the loadImage() loadMovie(), etc are almost all being changed to simply load() because the load image is implied from the context in the case of `ofImage.

In terms of documentation – the documentation has been updated – and it should be on the site after the next release. For example, see the note about internal use here https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/graphics/ofImage.h#L648-L663

2 Likes

thank you very much for the informative response. I suspected there was a desire to improve the consistency of behaviour behind the changes. It makes sense, even if I cannot be as lazy as I once was.

1 Like