OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Constructing TBitmap

You can construct a TBitmap object either directly or indirectly.

Using direct construction, you can specify the bitmap's width, height, and so on. Using indirect construction, you can specify an existing bitmap object, a pointer to a BITMAP structure, a metafile, a TDC device context, and more.

Here is the constructor for directly constructing a bitmap object:

TBitmap(int width, int height, uint8 planes=1, uint8 count=1, void* bits=0);

width and height specify the width and height in pixels of the bitmap. planes specifies the number of color planes in the bitmap. count specifies the number of bits per pixel. Either plane or count must be 1. bits is an array containing the bits to be copied into the bitmap. It can be 0, in which case the bitmap is left uninitialized.

You can create bitmap objects from existing bitmaps, either encapsulated in a

TBitmap object or contained in a BITMAP structure.
TBitmap(const TBitmap& bitmap);
TBitmap(const BITMAP far* bitmap);

TBitmap provides two constructors you can use to create bitmap objects that are compatible with a given device context. The first constructor follows:

TBitmap(const TDC& Dc, int width, int height, bool discardable = false);

It creates an uninitialized bitmap of the size height by width. Specifying true for the discardable parameter makes the bitmap discardable. A bitmap should never be discarded if it is the currently selected object in a device context.

The second constructor follows:

TBitmap(const TDC& Dc, const TDib& dib, uint32 usage);

It creates a bitmap compatible with the device represented by the device context from a DIB. The usage parameter should be CBM_INIT for 16-bit applications. CBM_INIT indicates that the bitmap should be initialized with the bits contained in the DIB object. If you do not specify CBM_INIT, the bitmap is created, but is left empty. CBM_INIT is the default.

32-bit applications can also specify CBM_CREATEDIB in the usage parameter. The CBM_CREATEDIB flag indicates that the color format of the new bitmap should be compatible with the color format contained in the DIB's BITMAPINFO structure. If the CBM_CREATEDIB flag is not specified, the bitmap is assumed to be compatible with the given device context.

You can also create bitmaps from the Windows Clipboard, from a metafile, or from a DIB object. To create a bitmap from the Clipboard, you only need to pass a reference to a TClipboard object to the constructor. The constructor gets the handle of the bitmap in the Clipboard and constructs a bitmap object from the handle, as follows:

TBitmap(const TClipboard& clipboard);

To create a bitmap from a metafile, you need to pass a TMetaFilePict &, a TPalette &, and a TSize &. The constructor initializes a device-compatible bitmap (based on the palette) and plays the metafile into the bitmap:

TBitmap(const TMetaFilePict& metaFile, TPalette& palette, const TSize& size);

To create a bitmap from a device-independent bitmap, you need to pass a TDib & to the constructor. You can also specify an optional palette. The constructor creates a device context and renders the DIB into a device-compatible bitmap:

TBitmap(const TDib& dib, const TPalette* palette = 0);

You can create a bitmap object by loading it from a module. This constructor takes two parameters, first the HINSTANCE of the module containing the bitmap and second the resource ID of the bitmap you want to load, as follows:

TBitmap(HINSTANCE, TResId);

You can also create a new TBitmap object from an existing HBITMAP handle, as follows:

TBitmap(HBITMAP handle, TAutoDelete autoDelete = NoAutoDelete);

This constructor is used to obtain an ObjectWindows object as an alias to a regular Windows handle received in a message.

See Also