TXImage
Source: source/classes/ximage.prg
Inherits from: TControl
TXImage is an extended image viewer control that supports zoom, rotation, brightness, contrast, gamma correction, alpha blending, grayscale conversion, and blur effects. It provides a built-in popup context menu with options for saving, printing, copying to clipboard, and image navigation.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cImageFile | Character | Path or identifier of the loaded image |
nZoom | Numeric | Zoom percentage (100 = original size) |
nRotate | Numeric | Rotation angle in degrees |
nSize | Numeric | Image dimension for size-based fitting |
cAlign | Character | Alignment string (e.g., "C" for center) |
nGamma | Numeric | Gamma correction value |
nBrightness | Numeric | Brightness adjustment |
nContrast | Numeric | Contrast adjustment |
nAlpha | Numeric | Alpha transparency level (0-255) |
lGray | Logical | Display the image in grayscale |
nBlur | Numeric | Blur radius |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nW, nH, bImage, oWnd ) | Create a new TXImage control. bImage can be a file name, bitmap handle, or a code block returning an image. |
Center() | Center the image within the control area |
FitWidth() | Scale the image to fit the control width |
FitHeight() | Scale the image to fit the control height |
FitRect() | Scale the image to fit entirely within the control |
FitOrglSize() | Restore the image to its original pixel dimensions |
Zoom( n ) | Set the zoom level to n percent |
Rotate( nDeg ) | Rotate the image by nDeg degrees |
SetSource( uNew ) | Replace the displayed image with a new source |
Paste() | Paste an image from the clipboard |
CopyToClipBoard() | Copy the current image to the clipboard |
Save( lAsViewed, cFile ) | Save the image to disk. If lAsViewed is .T., adjustments (zoom, effects) are preserved. |
Free Functions
| Function | Description |
|---|---|
XImage( uImage, cTitle ) | Display an image in a standalone viewer dialog window |
XImageArray( aImages, cTitle ) | Display a navigable array of images in a viewer dialog |
Example: Image Viewer with Context Menu
#include "FiveWin.ch"
function Main()
local oWnd, oImg
DEFINE WINDOW oWnd TITLE "Image Viewer" SIZE 800, 600
@ 10, 10 XIMAGE oImg FILE "photo.jpg" ;
SIZE 760, 540 OF oWnd
oImg:FitRect()
oImg:Rotate( 90 )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TXImage provides a built-in popup context menu activated by right-click, offering zoom, rotate, save, print, copy, and fit options at runtime.
- The free function
XImage()opens a modal dialog with a TXImage control and all standard toolbar actions. UseXImageArray()for browsing through multiple images. - Image adjustments (zoom, rotation, brightness, contrast, gamma, blur, grayscale, alpha) are applied in memory and do not modify the original source file unless explicitly saved with
Save(). - The
bImageparameter inNew()accepts a filename string, a bitmap handle (HBITMAP), or a code block that returns either.