TImage
Source: source/classes/image.prg
Inherits from: TControl
TImage is an extended image control that displays bitmaps, icons, and metafiles within a window or dialog. It extends TBitmap with additional capabilities: loading from files, resources, memory buffers, and URLs; saving images in various formats (BMP, PNG, JPG, GIF, TIFF); rotation; and a built-in progress indicator. TImage is the recommended control for displaying static images in FiveWin applications.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
nProgress | Numeric | Progress percentage (0-100). When set, a progress bar is overlaid on the image. |
nFormat | Numeric | Image format identifier used when saving. Values: 0=BMP, 1=JPG, 2=PNG, 3=GIF, 4=TIFF. |
cBmpFile | Character | Source file path of the displayed image. |
cBmpRes | Character | Resource name of the displayed image (if loaded from resources). |
hBitmap | Numeric (Handle) | Handle to the currently displayed bitmap. |
lStretch | Logical | If .T., the image is stretched to fit the control dimensions. |
lAdjust | Logical | If .T., the control size adjusts to match the image dimensions. |
nAngle | Numeric | Current rotation angle in degrees. |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, nW, nH, cRes, cFile, oWnd, lNoBorder, lStretch, lAdjust, oFont, bClrGrad, ... ) | Create a new image control. Accepts either a resource name (cRes) or file path (cFile). Additional parameters control border, stretch behavior, and gradient color. |
Define( cRes, cFile, oWnd ) | Alternative constructor for creating the control after instantiation. |
LoadImage( cRes, cFile ) | Load an image from a resource name or file path, replacing the current image. |
SaveImage( cFile, nFmt, nQuality ) | Save the current image to a file. nFmt specifies the format (0=BMP, 1=JPG, 2=PNG, 3=GIF, 4=TIFF). nQuality applies to JPG (0-100). |
LoadFromMemory( cBuf, nW, nH ) | Load an image from a memory buffer containing raw bitmap data. |
LoadFromURL( cUrl ) | Download and display an image from a URL. The image data is fetched via an internal HTTP request. |
RotateImage( nAngle ) | Rotate the displayed image by the specified angle in degrees. Creates a new rotated bitmap. |
Progress( lOn ) | Show or hide an overlaid progress indicator on the image. With no arguments, toggles visibility. |
SetImage( hBmp ) | Replace the displayed image with a bitmap handle. The previous bitmap is not destroyed (call DeleteObject() if needed). |
End() | Destroy the control and release the bitmap handle. |
Commands: @ ... IMAGE
@ nRow, nCol IMAGE oImg ;
[ FILENAME cFile ] ;
[ RESOURCE cRes ] ;
[ SIZE nW, nH ] ;
[ OF oWnd ] ;
[ NOBORDER ] ;
[ STRETCH ] ;
[ ADJUST ] ;
[ TRANSPARENT ]
Example: Load Image from File and Save as PNG
#include "FiveWin.ch"
function Main()
local oWnd, oImg
DEFINE WINDOW oWnd TITLE "TImage Demo" SIZE 600, 500
@ 20, 20 IMAGE oImg FILENAME "photo.bmp" ;
SIZE 560, 400 OF oWnd STRETCH
@ 440, 20 BUTTON "Save as PNG" SIZE 120, 30 OF oWnd ;
ACTION oImg:SaveImage( "photo.png", 2 ) // 2 = PNG
@ 440, 160 BUTTON "Rotate 90" SIZE 120, 30 OF oWnd ;
ACTION oImg:RotateImage( 90 )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TImage inherits from TControl, which inherits from TWindow. All standard control methods (
Move(),Refresh(),SetFocus(), etc.) are available. - The
STRETCHclause scales the image to fill the control dimensions. Without it, the image is drawn at its natural size. - The
ADJUSTclause resizes the control to match the loaded image's dimensions automatically. - Image formats supported for loading depend on the GDI+ libraries available on the system. BMP, PNG, JPG, GIF, and TIFF are universally supported on modern Windows.
SaveImage()uses GDI+ for format conversion. ThenQualityparameter (1-100) controls JPG compression level; higher values produce better quality but larger files.LoadFromURL()performs a blocking HTTP download. For non-blocking network image loading, consider usingTWebClientorFW_CurlHttp()to download the data first, thenSetImage().- The progress overlay is useful when loading large images or during batch processing. Call
oImg:Progress( .T. )to enable, then setoImg:nProgressto update the percentage.