ofImage loads and draws image files with a two-call setup/draw pattern
In openFrameworks, images are handled by the ofImage class. Images must be placed inside the project’s bin/data directory (or a subfolder). Loading happens once in setup() via the load() method, and rendering in draw() via draw(x, y) or draw(x, y, w, h) for a resized version. The top-left corner of the image is the default anchor point. Supported formats include .gif, .jpg, and .png. This setup/draw separation is the universal OF lifecycle pattern: expensive operations once at start, cheap rendering every frame.
Examples
// ofApp.h: ofImage myImg; // ofApp.cpp setup(): myImg.load(“images/photo.jpg”); // ofApp.cpp draw(): myImg.draw(0, 0); // or myImg.draw(190, 490, 20, 20) to resize
Assessment
Write the minimal ofApp.h declaration and the two ofApp.cpp lines needed to display a 320×240 PNG at position (100, 50); then explain why load() must not go in draw().