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

DATATypeDescription
nProgressNumericProgress percentage (0-100). When set, a progress bar is overlaid on the image.
nFormatNumericImage format identifier used when saving. Values: 0=BMP, 1=JPG, 2=PNG, 3=GIF, 4=TIFF.
cBmpFileCharacterSource file path of the displayed image.
cBmpResCharacterResource name of the displayed image (if loaded from resources).
hBitmapNumeric (Handle)Handle to the currently displayed bitmap.
lStretchLogicalIf .T., the image is stretched to fit the control dimensions.
lAdjustLogicalIf .T., the control size adjusts to match the image dimensions.
nAngleNumericCurrent rotation angle in degrees.

Methods

MethodDescription
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

See Also