Saving Bitmaps
 
 
 

The example below demonstrates how to save files for a multi-frame file.

First we declare a Bitmap pointer and a BitmapInfo instance.

Bitmap *bmap;
BitmapInfo bi;

To allow the user to choose an output file type, use the BitmapManager method SelectFileOutput(). This brings up the 'Browse Images for Output' dialog box. This method returns TRUE if the user selected a file; it returns FALSE if they cancel the dialog box. This method also handles checking if the filename chosen already exists, and if so provides an overwrite question dialog. This method will fill in the proper fields of the BitmapInfo passed.

BOOL gotIt = TheManager->SelectFileOutput(&bi, ip->GetMAXHWnd());
if (!gotIt) return; // User cancelled

Next we need to set the image size and the properties of BitmapInfo related to multi-frame images. Below we do this for a 30 frame sequence.

bi.SetWidth(640)
bi.SetHeight(480)
bi.SetFirstFrame(0)
bi.SetLastFrame(29)

With the BitmapInfo setup, we can call the BitmapManager to create the sequence:

bmap = TheManager->Create(&bi);

The next code is used to open the bitmap for output. This indicates to the system that the bitmap is open for output and we can write to.

bmap->OpenOutput(& bi);

Next we write the images for each frame:

for (frame = 0; frame < 30; frame++)
{
   // Do something to the image
   // ...
   // Write the image
   bmap->Write(&bi, frame);
}

When we are done we need to close the image:

bmap->Close(& bi)

Note: You can add any number of outputs to a bitmap. Just keep calling bmap->OpenOutput() with different outputs (for instance a TGA file and Frame Buffer). To write or close a specific output, use Write()and Close(). To write and close them all at once, use the Bitmap methods WriteAll() and CloseAll(). It is okay to use WriteAll() and CloseAll() if you have just one output defined.