libtcoddocumentation

5.1. Creating an image

Creating an empty image

You can create an image of any size, filled with black with this function.

TCODImage::TCODImage(int width, int height)

TCOD_image_t TCOD_image_new(int width, int height)

image_new( width, height)

ParameterDescription
width,heightSize of the image in pixels.
Example:

TCODImage *pix = new TCODImage(80,50);

TCOD_image_t pix = TCOD_image_new(80,50);

pix = litbcod.image_new(80,50)


Loading a .bmp or .png image

You can read data from a .bmp or .png file (for example to draw an image using the background color of the console cells).
Note that only 24bits and 32bits PNG files are currently supported.

TCODImage::TCODImage(const char *filename)

TCOD_image_t TCOD_image_load(const char *filename)

image_load(filename)

ParameterDescription
filenameName of the .bmp or .png file to load.
Example:

TCODImage *pix = new TCODImage("mypic.bmp");

TCOD_image_t pix = TCOD_image_load("mypic.bmp");

pix = libtcod.image_load("mypic.bmp")


Creating an image from a console

You can create an image from any console (either the root console or an offscreen console).
The image size will depend on the console size and the font characters size.
You can then save the image to a file with the save function.

TCODImage::TCODImage(const TCODConsole *console)

TCOD_image_t TCOD_image_from_console(TCOD_console_t console)

image_from_console(console)

ParameterDescription
consoleThe console to convert. In the C version, use NULL for the root console.
Example:

TCODImage *pix = new TCODImage(TCODConsole::root);

TCOD_image_t pix = TCOD_image_from_console(NULL);

pix = libtcod.image_from_console(0)


refreshing an image created from a console

If you need to refresh the image with the console's new content, you don't have to delete it and create another one. Instead, use this function. Note that you must use the same console that was used in the TCOD_image_from_console call (or at least a console with the same size).

void TCODImage::refreshConsole(const TCODConsole *console)

void TCOD_image_refresh_console(TCOD_image_t image, TCOD_console_t console)

image_refresh_console(image, console)

ParameterDescription
imageIn the C version, the image created with TCOD_image_from_console.
consoleThe console to capture. In the C version, use NULL for the root console.
Example:

TCODImage *pix = new TCODImage(TCODConsole::root); // create an image from the root console
// ... modify the console
pix->refreshConsole(TCODConsole::root);

TCOD_image_t pix = TCOD_image_from_console(NULL);
// ... modify the console ..
TCOD_image_refresh_console(pix,NULL);

pix = libtcod.image_from_console(0)
# ... modify the console ..
libtcod.image_refresh_console(pix,0)