Example: Fastgraph/Image Basics

Example FGIW1 illustrates fgi_open(), fgi_display(), and fgi_close(). The program first tries to open the EXAMPLE.FGI library. If it cannot do this, it displays an error message and exits. It then calls fgi_display() to display the CLOUDS.PCX image from the FGI library. We display the image using the palette values from the PCX file, and we perform color reduction to avoid conflicts with the Windows system colors if necessary. Finally, we call fgi_close() to close the FGI library.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

In Visual Basic, prefixing the FGI file name string with the App.Path property makes fgi_open() look for the file in the directory where the application's project (VBP) file resides when running the application from Visual Basic's development environment, or from the directory where the EXE file resides when running the application as an executable. If we don't do this, Visual Basic programs will look in the Visual Basic directory when running from the development environment. The PowerBASIC versions of the Fastgraph/Image examples include an AppPath() function that behaves the same way.

A few more points are worth mentioning about example FGIW1. First, Fastgraph's fg_move() function determines the reference point for displaying the image with fgi_display(). The reference point is the image's upper left corner unless displaying a pixel run file, in which case it is the image's lower left corner. This is consistent with Fastgraph's image display functions for these types of files.

This example ignores the value returned by fgi_display() to keep the program brief. In this simple example, we know CLOUDS.PCX is in the FGI library, so there's no need to monitor the return value. However, this may not always be true. In general, your programs should test the fgi_display() return value and take appropriate action if it is negative (indicating an error condition).

By default, fgi_display() uses Fastgraph's internal 4,096-byte buffer when displaying images. As with Fastgraph's image file display functions, we can use fg_imagebuf() to define our own image buffer. Using a larger buffer generally results in faster image display.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.