Adding images to vector

Hello,

I am new to Open Frameworks and would like to create a vector that would randomly select an image from 61 images.

Pseudo code

	ofApp.h
	#include "ofxThreadedImageLoader.h"
	
	
	std::vector<ofImage> images;
	ofxThreadedImageLoader loader;
	int imgSize = 61;
	
	
	ofApp.cpp
	//setup
	
	images.resize(imgSize);
	for(int i=0;i<imgSize;i++) {
		loader.loadFromDisk(images[i], pathToImage);
	}
	
	
	//draw
	int randomNr = ofRandom(imgSize);
	images[randomNr].draw(0, 0);

Thanks. How do I direct ofxThreadedImageLoader to the folder of images on my desktop?

loader.loadFromDisk(images[i], pathToImage);

Put your images to data folder and you can call it like here
loader.loadFromDisk(images[i], "Image"+ofToString(i) + ".jpg");

Nice — thank you!

How do I keep an image on the screen for longer? Like if I hit the spacebar, the image will stay put for 60 seconds.

The image is on the screen when you call it in draw(), it might be forever. You can have a global variable randomImg defined in ofApp.h and only change it when you hit the spacebar. If you want to change an image automatically you should use a timer in update (take a look at some examples).
What do you want to achieve?

I am working on an installation that alters images based on input from a motion sensor (I’ve done something similiar in processing in the past). The images will cycle randomly, but when the sensor reads motion in a particular range, the image would stay on the frame, and then will alter based on interaction with sensor (such as pixel sorting). The altered image would then replace the original image, so when it is pulled up again it is the altered version. At the moment I am building it in Xcode, though I hope to create a version that will run on Rasp Pi, which is one reason I am using OpenFrameworks since I don’t a version created via Processing would run well on the Pi.