GRAPHIC BITMAP LOAD statement

Purpose | Create a memory bitmap and load an image into it.
Syntax | GRAPHIC BITMAP LOAD BmpName$, nWidth&, nHeight& [,stretch&] TO hBmp???
BmpName$ | The name of the bitmap image to load.
nWidth& | The width of the bitmap, in pixels.
nHeight& | The height of the bitmap, in pixels.
stretch& | Stretch mode if the bitmap is to be resized.
hBmp??? | The bitmap handle.

Remarks

GRAPHIC BITMAP LOAD creates a new memory bitmap, loading a bitmap image from a resource or a disk file. This bitmap works just like a GRAPHIC WINDOW, except that it is not visible. The parameter BmpName$ specifies the name of the image to be loaded. If BmpName$ contains a period, it is presumed to be the name of a disk file. Otherwise, an attempt is made to load it from a resource -- if not found, it is then presumed to be a disk file.

The parameters nWidth& and nHeight& specify the width and height of the bitmap, in pixels. If either of the size parameters are zero (0), the bitmap is loaded at its natural size. If either of the size parameters is different from the natural size, the bitmap is stretched or condensed to the requested size.

If the bitmap creation is successful, the bitmap handle is assigned to the variable hbmp???. If not successful, hbmp??? is set to zero. When you are finished using this memory bitmap, you must delete it with GRAPHIC BITMAP END.

If the stretch& parameter is included, it is one of the values in the following table. If not included, or it is the value zero (0), the stretch mode is unchanged. An appropriate choice of stretch mode can substantially enhance the quality of bitmaps which are changed in size. The stretch mode equates are predefined in PowerBASIC.

The 4 stretch modes are:

%BLACKONWHITE | This is the default Windows stretch mode, and is most appropriate for monochrome bitmaps, or those with blocks of color. Performs a boolean OR of eliminated and existing pixels. It preserves black pixels at the expense of white pixels.
%WHITEONBLACK | Performs a boolean OR of eliminated and existing pixels. It preserves white pixels at the expense of black pixels.
%COLORONCOLOR | Deletes eliminated lines of pixels without trying to preserve their information.
%HALFTONE | This provides the highest quality for complex color bitmaps. The average color of the destination pixel block is kept approximately the same as the source pixel block.

The following code will retrieve the natural size of an image in a bitmap file, in pixels:

nFile& = FREEFILE

OPEN "myimage.bmp" FOR BINARY AS nFile&

GET #nFile&, 19, nWidth&

GET #nFile&, 23, nHeight&

CLOSE nFile&

See also | GRAPHIC BITMAP END, GRAPHIC BITMAP NEW, GRAPHIC GET STRETCHMODE, GRAPHIC IMAGELIST, GRAPHIC RENDER, GRAPHIC SET STRETCHMODE, GRAPHIC STRETCH