Saving and Loading a user created project file

Hi there,

I’m am developing a collaging iOS app, as part of it I need to have the collage projects able to be saved and loaded. The pieces to be saved are:
Background (ofImage) + Metadata (string)
Cuts: Per Cut - ofFbo, metadata string, ofMatrix4x4

I have been trying to do this with an xml and ofToString(), but I’ve run into problems, this approach [ string str = ofToString(fbo); ] doesn’t work.

Does anyone have any advice on a sensible approach for this?


Hi M,

I personally use Json and write something like this :

ofJson ofApp::storeFboParam(ofFbo f) {
    ofJson jsFbo;
    // put the parameters you want : 
   jsFbo["w"] = f.getWidth();
   jsFbo["h"] = f.getHeight();

    return jsFbo;  

then save it into a json file when exiting:

void ofApp::exit(){
    ofJson exitJson;
    ofJson jFbo = storeFboParam(myFbo);
    ofSaveJson("storeTest.json", exitJson);

following the json example.

I hope it helps.


Thanks Pierre,

Would that allow for image data to be stored? basically I’m cutting an ofImage to an FBO and then want to be able to store that whole FBO.

You could save your fbo to an image file, an save the name of the file in the .json config file. Then, when you want to load the image, you read the json and you load the image file. From the image file you can recreate your FBO.

right, ok thanks. so it sounds like there’s not a reliable way to save an FBO directly in that way, it would have to become an image first, then turned back into an FBO on load.
The cuts also have a path associated with them, this is used to check whether an interaction is within the irregularly cut fbo. I assume that I would need to save this ofPath too then?

another big tricky one is how to save the ofMatrix4x4, do you know of a way I could handle this too?

There is no direct way to do it. But a matrix can be see as a collection of vectors, and you can save a vector using ofJson.

Ah right ok, so sets of vec2f or something?
Pull them apart to save, and then put them back together on load?