ofImage loading from vector error

Hi there,

I have another recurring issue that is probably easy to solve but I haven’t been able to get to the bottom of it after a few days of struggles. I am trying to push_back images from a vector I created and it keeps returning this message: “No member named ‘push_back’ in ‘ofImage_’”

Here is my code for you to have a look. I would be so grateful if some of you can shine some light on this :slight_smile:

vector <ofImage> leaves; 
for(int i = 0; i < leaves.size(); i++) {
    leaves[i].push_back(); //here is where the error is occuring
    string imageName = "leaves" + ofToString(i) + ".png";
    leaves[i].resize(ofGetWidth(), ofGetHeight());



you might find it marginally quicker (and more readable) to do the things you want to your ofImage then push it into the vector

 vector <ofImage> leaves;
 int numOfImages = 5; // or however many i want to load
    for(int i = 0; i < numOfImages; i++) {
        ofImage newImage;
        string imageName = "leaves" + ofToString(i) + ".png";
        newImage.resize(ofGetWidth(), ofGetHeight());

Thank you so much, I think that did the trick in the setup.
I am still struggling to make the images actually be drawn. Is not a simple leaves.draw() or newImage.draw() enough within the draw() function in this instance?

to draw them you can access the position in the vector like this

leaves[i].draw(x,y, width, height);

just set up which image object in the vector you want to draw with i and then pass it usual image.draw() type parameters - either just an x and y value or x and y and width and height

this would draw all the images in the vector ‘leaves’ at random places on the screen in a 400x400 area

void ofApp::draw(){
    for (int i =0; i < leaves.size(); i++){
        int x = ofRandom(400);
        int y = ofRandom(400);

Thank you so so so so much. Vectors are one of the tougher topics for me as a beginner. I understand the concept but I struggle with implementation so this is a huge help!

lol ! I know what you mean - once you get the hang of it they are superhelpful>>

I made a video or two as part of a load of openFrameworks tutorials

this one introduces vectors in plain C++

I also did a series ‘programming for artists’ where i just draw stuff and write it in marker pen to walk thru programming ideas

Thank you for these, I will make sure to give them a spin. I just started my masters in creative computing so the artistic approach is very close to me :slight_smile:

good luck and welcome ! - the people here are very friendly and helpful - i’m doing a new series of tutorials making creative things called ‘openframeworks superBasics’ I post a new video each week - let me know if there are subjects/topics that would be useful