Overview

Graphics (Pixmap)

The System.Graphics unit provides the TPixmap class for low-level 2D buffer manipulation.

TPixmap Class

Member Description
GetPixel / SetPixel Accesses ARGB color at (x, y).
GetData / SetData Accesses ARGB color by linear pixel index (offset).
Resize(w, h) Resizes the pixmap (nearest neighbor).
ToPNGData(w, h, alpha) Returns PNG data as a string.
ToJPEGData(w, h, qual, opts) Returns JPEG data as a string.
ToHexString Returns raw buffer data as hex string.
AssignHexString(hex) Fills buffer from a hex string.
Length Total size in bytes (width * height * 4).

Global Functions

Function Description
CreatePixmap(w, h) Creates a new TPixmap instance (initialized to zero/black).
PNGDataToPixmap(data, alpha, @w, @h) Creates a pixmap from PNG data, returning dimensions in w and h.
JPEGDataToPixmap(data, scale, @w, @h) Creates a pixmap from JPEG data, returning dimensions in w and h.

Colors

Colors are represented as 32-bit ARGB integers in the format $AARRGGBB.

  • $FFFF0000: Opaque Red
  • $FF00FF00: Opaque Green
  • $FF0000FF: Opaque Blue
  • $80000000: Semi-transparent Black

Example: Basic Operations

// Create a 64x64 pixmap (initialized to black)
var bmp := CreatePixmap(64, 64);

for var i := 0 to 63 do
  bmp.SetPixel(i, i, $FFFFFFFF); // White diagonal

var hex := bmp.ToHexString;

Performance

For heavy pixel processing, consider using GetData and SetData with linear indexing to avoid the overhead of coordinate calculations.

var bmp := CreatePixmap(100, 100);
// Linear fill (much faster for full-buffer operations)
for var i := 0 to (bmp.Length div 4) - 1 do
  bmp.SetData(i, $FF00FF00); // Fill with green
On this page