ofImage.saveImage() to ofBuffer. How do I know what is in the buffer?

Hi image manipulation experts,

ofImage has the option of writing to an ofBuffer using saveImage(). I’m doing this so that I can prepare a compressed image to send over UDP:

cameraImage.saveImage(cameraSendBuffer, OF_IMAGE_QUALITY_HIGH);

I know that there is data in cameraImage because I’m drawing it to screen. However, I’ve no idea what to expect to find in cameraSendBuffer or how to query the data. I don’t know how much data has been written and I’m not sure whether it has been written as a jpeg or another compression format.

I need a char * and a length value so that I can send the compressed data. I also need to know if this is indeed jpeg format, so that I can pick it up at the other end. Can anyone help work this out?

Additional notes:
I’ve seen some solutions using FreeImage but they’re pretty confusing.
I’ve tried allocating the buffer with some space. It is not clear whether or not this is necessary. Doesn’t seem to help. If I don’t allocate then I get a size of zero after the operation. If I do allocate I get the allocated size after the operation.

yes, that call should have a format specifier, i’ll add it later for next version. in any case you can use:


or any of the other OF_IMAGE_FORMAT_*.

then you can get the char* and the size of the buffer by calling:

char * data = cameraSendBuffer.getBinaryBuffer();
int size = cameraBuffer.size();

Thank you!
I must have been very close to that but it would have taken me hours to work it out!

As a bonus question, the pixels I’m grabbing are from ofxRPiCameraVideoGrabber. Is there any way I can grab the camera image already compressed?