Creating and modifying images
In the preceding sections, we considered different ways of drawing images loaded from files. In this section, we see how to generate new images or alter an existing image by specifying its pixels directly.
A raster image is represented as an array of pixels in memory. If we have an image with width w
pixels and height h
pixels, it is represented by N = w * h
pixels. Normally, the horizontal rows of an image lie sequentially in memory: the w
pixels of the first row, then the second row, and so on to the h
row.
The pixels of the image can hold differing amounts of information depending on the image type. In openFrameworks, the following types are used:
The
OF_IMAGE_COLOR_ALPHA
type denotes a colored image with transparency. Here, each pixel is represented by 4 bytes, holding red, green, blue, and alpha color components respectively, with values from 0 to 255.The
OF_IMAGE_COLOR
type denotes colored image without transparency. Here each pixels is represented by 3...