Loading and drawing an image
For loading and drawing an image, you need to declare the image object, load the image from a file, and add a drawing function call in the testApp::draw()
function. Perform the following steps:
Declare the image as an
ofImage
object:ofImage image;
The best way is to declare images in the
testApp
class declaration in thetestApp.h
file. For simplicity, sometimes we will declare them right on top of thetestApp.cpp
file.Load an image from a file using the
loadImage
function:image.loadImage( fileName );
Here,
fileName
is a string value specifying the filename; for example,sunflower.png
. Normally, images should be located in thebin/data
folder of your application. If you want to use an image from another folder, it is possible to use absolute paths; for example,image.loadImage( "C:\\myimage.png" )
in Windows.Draw the image using the
image.draw( x, y )
function inside thetestApp::draw()
function. Here,x
andy
are float values specifying the top-left corner of the...