GDI+ Classes
Source: source/classes/tgdiplus.prg
Standalone classes: Graphics, Pen, Brush, GDIBmp, Path, Region
FiveWin provides a comprehensive set of GDI+ wrapper classes for high-quality 2D rendering with anti-aliasing, alpha transparency, gradient brushes, path-based drawing, and image processing. These classes wrap the Windows GDI+ flat API and require no external ActiveX components. GDI+ is initialized automatically when the first class is instantiated.
Graphics Class
The main drawing surface. All drawing operations begin with a Graphics object.
| Method | Description |
|---|---|
New( hDC [, lNoHighQuality] ) | Create from a device context handle |
NewWnd( hWnd [, lNoHighQuality] ) | Create for window drawing |
NewFromWnd( oWnd [, lNoHighQuality] ) | Create from a TWindow object |
NewImg( hImg [, lNoHighQuality] ) | Create for off-screen image rendering |
SetHighQuality() | Enable anti-aliased rendering |
SetNormalQuality() | Disable anti-aliasing for speed |
DrawLine( oPen, nLeft, nTop, nRight, nBottom ) | Draw a line |
DrawRect( oPen, oBrush, nLeft, nTop, nWidth, nHeight ) | Draw a rectangle |
DrawEllipse( oPen, oBrush, nLeft, nTop, nWidth, nHeight ) | Draw an ellipse |
DrawArc( oPen, nLeft, nTop, nW, nH, nStartAngle, nSweepAngle ) | Draw an arc |
DrawRoundRect( oPen, oBrush, nLeft, nTop, nW, nH, nRadius ) | Draw a rounded rectangle |
DrawPath( oPen, oPath ) | Draw a graphics path outline |
FillPath( oBrush, oPath ) | Fill a graphics path |
DrawImage( oImage, nTop, nLeft [, nW, nH] ) | Draw an image |
Clear( nTrans, nRed, nGreen, nBlue ) | Clear the surface with an ARGB color |
Translate( nRow, nCol ) | Translate the coordinate system |
Rotate( nAngle ) | Rotate the coordinate system |
Scale( nX, nY ) | Scale the coordinate system |
Destroy() | Release the GDI+ graphics object |
GDI+ Pen Class
GDI+ pen for drawing lines with color, width, and style.
| Method | Description |
|---|---|
New( nAlpha, nR, nG, nB, nSize ) | Create a pen with ARGB color and size. Alpha 0..255. |
SetColor( nAlpha, nR, nG, nB ) | Change pen color |
SetSize( nSize ) | Change pen width |
SetStyle( nStyle ) | Set pen style (e.g., GDI_PEN_ROUND for rounded ends) |
SetLineJoin( nJoin ) | Set line join style |
Destroy() | Release the GDI+ pen |
GDI+ Brush Class
GDI+ brush for filling shapes with solid colors or gradients.
| Method | Description |
|---|---|
NewSolidBrush( nAlpha, nR, nG, nB ) | Create a solid ARGB brush |
NewGradientBrush( nTop, nLeft, nW, nH, nType, nA1, nR1, nG1, nB1, nA2, nR2, nG2, nB2 ) | Create a linear gradient brush. nType: 0=horizontal, 1=vertical, 2=diagonal-right, 3=diagonal-left. |
AngleGradientBrush( ... nAngle, lScala ) | Create a gradient at an arbitrary angle |
Destroy() | Release the GDI+ brush |
GDIBmp Class
GDI+ bitmap for loading, manipulating, and saving images.
| Method | Description |
|---|---|
New( cFile ) | Load an image from file (BMP, JPG, GIF, TIF, PNG, EMF, WMF, ICO) |
Resize( nWidth, nHeight ) | Resize the image (maintains aspect ratio if one dimension is omitted) |
Rotate( nRotate ) | Rotate/flip the image |
ImageRotate( nDegrees ) | Rotate by arbitrary angle |
Save( cFile [, nQuality] ) | Save to file. nQuality applies to JPEG (0-100). |
GetWidth() / GetHeight() | Return image dimensions |
CreateThumbnail( nW, nH ) | Create a thumbnail GDIBmp |
Conver24to32Alpha() | Convert 24-bit to 32-bit with alpha transparency |
GetGDIHbitmap() | Extract a GDI bitmap handle for use with GDI functions |
End() / Destroy() | Release the GDI+ image |
Path Class
GDI+ graphics path for complex shape construction.
| Method | Description |
|---|---|
New() | Create an empty path |
AddLine( nLeft, nTop, nRight, nBottom ) | Add a line segment |
AddArc( nLeft, nTop, nW, nH, nStartAngle, nSweepAngle ) | Add an arc |
AddRectangle( nLeft, nTop, nRight, nBottom ) | Add a rectangle |
AddRoundRect( x, y, nW, nH, nRadius ) | Add a rounded rectangle |
AddElipse( nTop, nLeft, nW, nH ) | Add an ellipse |
AddString( cText, cFont, nStyle, eMSize, ... ) | Add text as a path outline |
StarFigure() / CloseFigure() | Begin/close a figure within the path |
Translate() / Rotate() / Scale() | Transform the path |
Destroy() | Release the path |
Region Class
| Method | Description |
|---|---|
NewFromPath( oPath ) | Create a GDI+ region from a Path object |
IsRegionVisible( nX, nY, oGraphics ) | Test if a point is visible in the region |
Destroy() | Release the region |
Example
#include "FiveWin.ch"
function Main()
local oWnd, oGraphics, oPen, oBrush
DEFINE WINDOW oWnd TITLE "GDI+ Demo" SIZE 500, 400
oWnd:bPainted = {| hDC |
local oGraphics := Graphics():New( hDC )
local oPen := Pen():New( 255, 255, 0, 0, 3 ) // Red pen, 3px
local oBrush := Brush():NewSolidBrush( 128, 0, 0, 255 ) // Semi-transparent blue
// Draw a red ellipse outline
oGraphics:DrawEllipse( oPen, oBrush, 50, 50, 200, 150 )
// Semi-transparent blue fill is applied automatically by DrawEllipse
oPen:Destroy()
oBrush:Destroy()
oGraphics:Destroy()
}
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- GDI+ is initialized automatically via an
init procedure GdiPlusStart()and shut down viaexit procedure GdiPlusEnd(). No manual startup/shutdown is needed. - All GDI+ classes are standalone in the sense that they do not derive from TControl or any other FiveWin base class.
- GDIBmp supports loading from file, from resource (PNG or bitmap), and from memory string. Supported input formats: BMP, JPG, GIF, TIF, PNG, EMF, WMF, ICO. Output formats: BMP, JPG, GIF, TIF, PNG.
- The Graphics class sets page unit to pixels by default and enables high quality (anti-aliased) rendering unless
lNoHighQualityis .T.