TBitmap
Fonte: source/classes/bitmap.prg
Inherits from: TControl
TBitmap is a control that displays a bitmap image from a file, resource, or handle. It supports zoom, transparency, alpha blending, stretch modes, and scrollable large images. The control can display BMP files embedded as resources or loaded from disk.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hBitmap | Handle | Handle to the bitmap GDI object |
hPalette | Handle | Handle to the bitmap color palette |
cBmpFile | Character | Bitmap file path on disk |
cResName | Character | Bitmap resource name embedded in the EXE |
nZoom | Numeric | Zoom factor (1 = original size) |
lTransparent | Logical | Enable transparent background drawing |
lStretch | Logical | Stretch bitmap to fit the control dimensions |
nImgWidth | Numeric | Original bitmap width in pixels |
nImgHeight | Numeric | Original bitmap height in pixels |
lHasAlpha | Logical | Whether the bitmap has an alpha channel |
aHotAreas | Array | Array of clickable hot areas on the bitmap |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nW, nH, cRes, cFile, lNoBorder, oWnd, bLClicked, bRClicked, lScroll, lStretch, oCursor, cMsg, lUpdate, bWhen, lPixel, bValid, lDesign ) | Create a new bitmap control |
ReDefine( nId, cRes, cFile, oWnd, ... ) | Redefine from a dialog resource placeholder |
LoadImage( cResName, cBmpFile ) | Load bitmap from resource name or disk file |
LoadBMP( cBmpFile ) | Load a bitmap from disk by filename |
SetBMP( cResName ) | Load a bitmap from a resource name |
Zoom( nZoom ) | Set zoom level (1=100%, 2=200%, etc.) |
SaveToBmp( cFile ) | Save the current bitmap to a file on disk |
Paint() | Draw the bitmap onto the control surface |
Center() | Center the bitmap within the control area |
CopyToClipboard() | Copy bitmap image to the clipboard |
HasAlpha() | Check if the bitmap has an alpha channel |
Example: Load and Display a Bitmap
#include "FiveWin.ch"
function Main()
local oWnd, oBmp
DEFINE WINDOW oWnd TITLE "TBitmap Demo" SIZE 600, 450
@ 10, 10 BITMAP oBmp OF oWnd ;
FILE "c:\fwh\bitmaps\olga1.bmp" ;
SIZE 300, 200
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- Use the
BITMAP ... FILE cFileclause to load from disk, orBITMAP ... RESOURCE cResfor embedded resources. - The
nWidthandnHeightaccess methods return the zoomed bitmap dimensions automatically based on the original image size and::nZoom. - Enable
lScrollto show scrollbars when the bitmap is larger than the control area. UselStretchto fit the bitmap to the control rectangle. - The
aHotAreasarray can define clickable regions on the bitmap for interactive image maps.