Loading Bitmaps

The following code demonstrates how to load a bitmap using BitmapManager::SelectFileInput() to allow the user to choose a file to load (and initialize the BitmapInfo instance passed to it).

First we declare a Bitmap pointer and a BitmapInfo instance.

Bitmap *bmap;
BitmapInfo bi;

Next, we use a method of the bitmap manager to allow the user to choose an image file. This method returns FALSE if the user cancels and TRUE if they select an image. If you want to directly indicate which file to load, just set the fields of BitmapInfo yourself (for example .SetName(_T("TEST.JPG")); )

// Let the user choose the file to open
BOOL res = TheManager->SelectFileInput(&bi, ip->GetMAXHWnd(), _T("Open File"));
 
if (!res) return; // User cancelled...

After SelectFileInput() returns, the BitmapInfo instance passed to it contains the necessary information about the bitmap to load. To load the bitmap, the Load() method of the bitmap manager is used.

// Load the selected image
BMMRES status;
bmap = TheManager->Load(&bi, &status);
if (status != BMMRES_SUCCESS)
{
   MessageBox(ip->GetMAXHWnd(), _T("Error loading bitmap."),
   _T("Error"), MB_ICONSTOP);
}

Once the image is loaded, you can work with it like any other bitmap. For example to display the bitmap in a window, use the Bitmap::Display() method.

// Display the opened bitmap
bmap->Display(title, BMM_CN, FALSE, TRUE);

A few more notes on the bitmap manager Load() method -- Additional options may be set by calling BitmapManager::ImageInputOptions() before calling Load(). This method will ask the user for special details such as custom positioning of smaller/larger images, etc. This method sets the proper fields in BitmapInfo.