Game Development Reference
In-Depth Information
It is highly recommended that we use lossless file formats, such as PNG, to create a high-
quality experience for the user. Lossy formats such as JPEG will degrade the quality of
the image while proving greater compression. We should only consider using JPEGs when
the program size matters, or we are not concerned with the quality of the images. For ex-
ample, we can also choose to use JPEGs for large images (such as backgrounds) with a
carefully selected compression level that will save us a lot of space, while providing min-
imal quality degradation.
The Image class provides very useful methods to manipulate an image. Functions such
as Image::getPixel() and Image::setPixel() allow us to change individual
pixels. If we want to read all pixels from an image, there is the
Image::getPixelPtr() function, which returns the beginning of the pixel array.
This array is in the same format as the array we used to create the image in our second ex-
ample. Apart from that, Image::flipHorizontally () and
Image::flipVertically() transform the whole image by flipping its pixels in a
particular direction. Finally, we can save the image to a file by calling
Image::saveToFile() and passing a filename. The supported formats for saving an
image are: bmp , png , tga , and jpg .
Now that we know how to create and manipulate images, let's see how to create textures
out of them.
Search WWH ::

Custom Search