Example: Image Files

The Image example uses many of Fastgraph's image display, creation, and management functions. It lets you display and create BMP and PCX files, display JPEG files, and play FLI/FLC and AVI files (continuously or one frame at a time). In addition, Image provides a way to display details about the currently displayed image. As far as Windows resources, Image uses a top-level menu, with pull-down menus for each image file type in the top-level menu, plus dialog boxes for selecting file names. The pull-down menu for BMP files looks like this:

Initially, the BMP menu only lets you open (display) a BMP file, but once you do, its Make and Details items are also enabled, as is the Make item on the PCX menu. The PCX menu is the same as the BMP menu, and the JPEG menu is also the same except for the lack of a Make item. The FLI/FLC and AVI menus include items to open a file (which plays its first frame), play a file continuously (until Escape is pressed), play the next frame of the file, rewind it, and obtain information about it.

Each Open and Make menu item obtains the image file name using the Open File or Save File dialog boxes from the Windows common dialog box library. The C++Builder, MFC, Delphi, and Visual Basic versions of Image simply use the common dialog box controls. For the C/C++ version, however, things are more involved. We interface to the common dialog boxes through the program's GetOpenFilename() and GetSaveFilename() functions. As the point of the Image program is to demonstrate Fastgraph's image file functions, we won't delve into the mechanics of these two functions here. Suffice it to say, GetOpenFilename() and GetSaveFilename() each store the name of the selected file, including full path information, in the FileName global. Both functions return OK if we selected a file, and ERR if we didn't (for example, if we pressed the Cancel button in the dialog box).

The Image program's WM_CREATE handler creates an initial 32x32 virtual buffer. Because the image files that Image loads can be any size, we create a virtual buffer with the same dimensions as the image when we load the image. Before we do this, however, we release the virtual buffer containing the previously loaded image (the program's SwitchBuffers() function handles these tasks). Creating the 32x32 virtual buffer eliminates the need for SwitchBuffers() to treat the first image it loads as a special case (we chose the 32x32 size because some Windows display drivers treat smaller drawing surfaces inconsistently). The SwitchBuffers() function creates a 256-color virtual buffer when loading a palette-based image file, or a 24-bit true color virtual buffer when loading a direct color image file.

menu items

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.