Overview

Pixmap Formats

TPixmap image formats (PNG & JPEG)

Source Code

// TPixmap image formats (PNG & JPEG)
uses System.Encoding;

// Create a small 32x32 pixmap (implicitly black)
var bmp := CreatePixmap(32, 32);

// Draw a simple red cross
for var i := 0 to 31 do begin
   bmp.SetPixel(i, i, $FFFF0000);
   bmp.SetPixel(31 - i, i, $FFFF0000);
end;

// Convert to PNG (with alpha)
var pngData := bmp.ToPNGData(-1, -1, True);
PrintLn('PNG Size: ' + IntToStr(pngData.Length) + ' bytes');
PrintLn('PNG Base64: ' + Base64Encoder.Encode(pngData).Copy(1, 40) + '...');

// Convert to JPEG (quality 75)
var jpgData := bmp.ToJPEGData(-1, -1, 75);
PrintLn('JPEG Size: ' + IntToStr(jpgData.Length) + ' bytes');

// Round-trip: PNG to Pixmap
var w, h : Integer;
var bmp2 := PNGDataToPixmap(pngData, True, w, h);
PrintLn('Recovered PNG Dimensions: ' + IntToStr(w) + 'x' + IntToStr(h));

// Round-trip: JPEG to Pixmap (half scale)
var w2, h2 : Integer;
var bmp3 := JPEGDataToPixmap(jpgData, 2, w2, h2);
PrintLn('Recovered JPEG Dimensions (1/2 scale): ' + IntToStr(w2) + 'x' + IntToStr(h2));

// Resize pixmap
bmp.Resize(16, 16);
PrintLn('Pixmap resized to 16x16');

Result

PNG Size: 223 bytes
PNG Base64: iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABz...
JPEG Size: 796 bytes
Recovered PNG Dimensions: 32x32
Recovered JPEG Dimensions (1/2 scale): 16x16
Pixmap resized to 16x16
On this page