DevIL Logo
      A full featured cross-platform image library.


About

News

Download

SourceForge Home

Documentation
Tutorials

Logos

Links

Projects

Contact Us

Tutorial 6: Saving ImagesLast Revised: 6:51 PM 11/26/2000
Saving Images
DevIL doesn't go as crazy with image saving as much as it does with loading images, but it still performs this task quite well, with a multitude of image formats supported: Bitmap (.bmp), C Header (.h), Jpeg (.jpg, .jpe, .jpeg), ZSoft Pcx (.pcx), Portable Anymap (.pbm, .pgm, .ppm), Portable Network Graphics (.png), Sgi (.sgi, .bw, .rgb, .rgba) and Truevision Targa (.tga) images.

There are only two functions to save images:
ILboolean ilSave(ILenum Type, char *FileName);
ILboolean ilSaveImage(char *FileName);

There is one function to save palettes:
ILboolean ilSavePal(char *FileName);


Saving Images Explained
To save an image, there must first be a current image bound. Read the tutorial on Binding Images to learn how to accomplish this. Unlike loading, saving only works with filenames. ilSaveImage determines what type of image to save based on the filename's extension. For instance, if the filename is monkey.tga, the image will be saved as a Truevision Targa file. If the current bound image is in a format that is not support by the destination file, DevIL will automatically convert the current image to a format natively support by the destination file format. The current image is actually left alone, and a copy is made, which is converted, saved, then deleted, so there is no fear of DevIL destroying your carefully constructed images.

Example of ilSaveImage

ilSaveImage("monkey.tga");

ilSave is almost exactly like ilSaveImage, but instead of letting DevIL determine what type of file should be saved based on the extension, you tell DevIL what to save the file as. The Type enum specifies what type of file to save the current image as. To find the accepted values for Type, read the ilLoad docs. If IL_TYPE_UNKNOWN is passed as the Type parameter, ilSave behaves exactly like ilSaveImage. In fact, ilSave calls ilSaveImage.

Example of ilSave
ilSave(IL_TGA, "monkey.tga");

If there is an image format you would like DevIL to use but don't want to modify the library, you can register your own function from your application that will let DevIL save new image formats. For more information on this feature, click here.

Overwriting Files
By default, DevIL will never overwrite any existing files. This is to prevent DevIL from accidentally overwriting your porn...err...family photo collection. Use ilEnable with the IL_FILE_OVERWRITE parameter to force DevIL to overwrite existing files if names collide.

Example of Overwriting Files
ilEnable(IL_FILE_OVERWRITE);
ilSave("monkey.tga", IL_TGA);
ilSave("monkey.tga");


Saving Palettes
If the current bound image has a palette, then ilSavePal saves the palette to FileName. If not, IL_FALSE is returned, and the IL_INVALID_EXTENSION error is set. Right now, only Paint Shop Pro palettes (.pal) are saved.