Drawing in offscreen images.

Hi… I have a basic question about images. I want to create a load of images in memory and draw onto them (ellipses, rects, lines etc), but without actually drawing to the screen. Later on I might want to actually draw one (or more) of these images to the screen. What is the best way of doing this?


To give a bit more information - I am writing a program that uses a hill climbing algorithm with a fitness function. I need to send the current screen image to a method that draws some stuff on it (offscreen), and checks the fitness. If the fitness is greater than the current screen image, the current screen image is replaced with the offscreen one. So I have a need to create an image offscreen to draw into - but which can also be passed to the fitness function (which takes an image and returns a float).

I have implemented this in Processing - with a “mutate” method which takes a PImage, draws on it, and returns a new PImage. I was just wondering if you could do this with an ofImage. (in Processing, if img is a PImage you can’t do img.rect(), etc…you have to copy into a PGraphics object, draw on it, and then copy back to a new PImage)

So I guess what I am really trying to do is write a mutate method that takes an ofImage, draws stuff on it, and then returns an ofImage which then be passed to the fitness method, which takes an ofImage and returns a float.

I think this is solved now:


Sorry for the crosspost, but Zach asked me to post it with that particular title, and I put it in the advanced section as it seemed more appropriate there.