The Bitmap Editor Application > Step 2: Implementing the Document and the View > Reading a Bitmap
 
Reading a Bitmap
A document is read when:
*The user chooses File > Open from the application menu bar,
*or, when selecting the Open button from the toolbar,
*or, with the CTRL-O accelerator.
The association between the user action and the document action is automatically performed by Application Framework.
When the user chooses File > Open, Application Framework calls the BitmapDocument::readDocument method. This method will be overridden to implement the actual work performed when reading a bitmap file.
IlvBoolean
BitmapDocument::readDocument(const IlvPathName& pathname)
{
IlvDisplay* display = getDisplay();
// Read the bitmap
IlvBitmap* bitmap = display->readBitmap(pathname);
// If the bitmap has not been read correctly
if (!bitmap || bitmap->isBad()) {
delete bitmap;
IlvFatalError("Cannot load %s bitmap !", getPathName());
return IlvFalse;
} else {
// The bitmap read by readBitmap is a shared bitmap.
// Here you do not want to use a shared bitmap because the editor may
// modify it. So, the name set by the call to IlvDisplay::readBitmap
// is removed.
bitmap->setName(0);
setBitmap(bitmap);
setPalette(display->defaultPalette());
return IlvTrue;
}
}
Note: The default implementation of the IlvDvDocument::readDocument method calls the serialize virtual method. Another way to deal with I/O inside a document is to override only the serialize method. However, the serialize method cannot be used here because the bitmap must be read using its full path; the method used to read the bitmap takes a string as parameter (IlvDisplay::readBitmap(const char*)), whereas the serialize method takes a stream as parameter. See the Reference Manual for more information on the IlvDvDocument::readDocument and IlvDvDocument::serialize methods.
The Bitmap Editor application is now able to read bitmap files and to store the bitmap data in the BitmapDocument class.

Version 5.5.1
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.