# Graphics (Pixmap)
DWScript provides built-in support for low-level 2D buffer manipulation through the `TPixmap` class. No `uses` clause is required.
## 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. |
## 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
```pascal
// 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;
// OUTPUT NONE
```
:::info
### Performance
For heavy pixel processing, consider using `GetData` and `SetData` with linear indexing to avoid the overhead of coordinate calculations.
```pascal
// NO_RUN
var bmp := CreatePixmap(100, 100);
// Linear fill (faster for full-buffer operations)
for var i := 0 to (100 * 100) - 1 do
bmp.SetData(i, $FF00FF00); // Fill with green
```
:::
Graphics (Pixmap)
DWScript provides built-in support for low-level 2D buffer manipulation through the TPixmap class. No uses clause is required.
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.
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);forvar i :=0to63do
bmp.SetPixel(i, i,$FFFFFFFF);// White diagonalvar hex := bmp.ToHexString;
Performance
For heavy pixel processing, consider using GetData and SetData with linear indexing to avoid the overhead of coordinate calculations.
// NO_RUNvar bmp := CreatePixmap(100,100);// Linear fill (faster for full-buffer operations)forvar i :=0to(100*100)-1do
bmp.SetData(i,$FF00FF00);// Fill with green