Introduction

Pixmap (code) encapsulates image data resident in memory. It supports simple file loading and draw operations for basic image manipulation. The most typical use is preparation of an image for upload to the GPU by wrapping in a Texture (code) instance. There are also methods for image saving/loading through the PixmapIO (code) class. PixmapIO supports uncompressed PNG as well as CIM, a compression format peculiar to libGDX which is useful for quick storage access such as during state saving/loading between application focus changes. As a Pixmap resides in native heap memory it must be disposed of by calling

Pixmap Creation

byte array containing image data encoded as JPEG, PNG or BMP, a FileHandle (code), or a specification of dimensions and a format. Once created it can be further manipulated before being uploaded to an OpenGL Texture (code) for rendering or saved for some future use. The following example creates a 64x64 32-bit RGBA Pixmap, draws a filled green circle inside it, uploads it to a Texture and then disposes of the memory:

  1. Pixmap pixmap = new Pixmap( 64, 64, Format.RGBA8888 );pixmap.setColor( 0, 1, 0, 0.75f );pixmap.fillCircle( 32, 32, 32 );Texture pixmaptex = new Texture( pixmap );pixmap.dispose();

unmanaged as it was not created from a persistent file, but a volatile piece of memory which was subsequently discarded. The next example shows a pause/resume life cycle of a typical Android application:

  1. FileHandle dataFile = Gdx.files.external( dataFolderName + "current.cim" );@Overridepublic void pause() { Pixmap pixmap; // do something with pixmap... PixmapIO.writeCIM( dataFile, pixmap );}@Overridepublic void resume() { if ( dataFile.exists() ) { Pixmap pixmap = PixmapIO.readCIM( dataFile ); // do something with pixmap... }}

pixmap will be written to an external location using a simple compression scheme upon application focus loss, and subsequently upon regaining focus it will be reloaded if extant at the specified location.

Drawing

setColor(), setBlending(), and setFilter() respectively.