PixelFormat 列舉定義每像素位元組織。建立 TGPBitmap 時指定格式,決定色彩精度、記憶體佔用、Alpha 支援。本文列出所有 24 種格式常數、Delphi/微軟名稱對照與中文說明。
var
g, gbit: TGPGraphics;
bit1, bit2: TGPBitmap;
sb: TGPSolidBrush;
begin
g := TGPGraphics.Create(Canvas.Handle);
sb := TGPSolidBrush.Create(MakeColor(255, 255, 0, 0)); // 紅色筆刷
bit1 := TGPBitmap.Create(200, 32, PixelFormat32bppARGB); // 32 位真彩色 + Alpha
bit2 := TGPBitmap.Create(200, 32, PixelFormat1bppIndexed); // 僅黑白兩色
gbit := TGPGraphics.Create(bit1);
gbit.FillRectangle(sb, 0, 0, 200, 32);
g.DrawImage(bit1, 11, 11, bit1.GetWidth, bit1.GetHeight); // 顯示紅色
gbit := TGPGraphics.Create(bit2);
gbit.FillRectangle(sb, 0, 0, 200, 32);
g.DrawImage(bit2, 11, 100, bit2.GetWidth, bit2.GetHeight); // 顯示黑色 (僅黑白)
sb.Free; bit1.Free; bit2.Free; gbit.Free; g.Free;
end;
| Delphi 常數 | 微軟名稱 | 說明 |
|---|---|---|
| PixelFormat1bppIndexed | Format1bppIndexed | 1 位元/像素,索引色 (2 色) |
| PixelFormat4bppIndexed | Format4bppIndexed | 4 位元/像素,索引色 (16 色) |
| PixelFormat8bppIndexed | Format8bppIndexed | 8 位元/像素,索引色 (256 色) |
| PixelFormat16bppGrayScale | Format16bppGrayScale | 16 位元灰階 (65536 階) |
| PixelFormat16bppRGB555 | Format16bppRgb555 | 16 位元,R5G5B5 (保留 1 位) |
| PixelFormat16bppRGB565 | Format16bppRgb565 | 16 位元,R5G6B5 |
| PixelFormat16bppARGB1555 | Format16bppArgb1555 | 16 位元,A1R5G5B5 |
| PixelFormat24bppRGB | Format24bppRgb | 24 位元,R8G8B8 |
| PixelFormat32bppRGB | Format32bppRgb | 32 位元,R8G8B8 (保留 8 位) |
| PixelFormat32bppARGB | Format32bppArgb | 32 位元,A8R8G8B8 (標準) |
| PixelFormat32bppPARGB | Format32bppPArgb | 32 位元,預乘 Alpha |
| PixelFormat48bppRGB | Format48bppRgb | 48 位元,R16G16B16 |
| PixelFormat64bppARGB | Format64bppArgb | 64 位元,A16R16G16B16 |
| PixelFormat64bppPARGB | Format64bppPArgb | 64 位元,預乘 Alpha |
| PixelAlpha | Alpha | 像素資料含未預乘 Alpha |
| PixelCanonical | Canonical | 標準格式 (32bpp ARGB) |
| PixelDontCare | DontCare | 未指定格式 |
| PixelExtended | Extended | 保留 |
| PixelGdi | Gdi | GDI 相容色彩 |
| PixelIndexed | Indexed | 索引色模式 |
| PixelMax | Max | 列舉最大值 |
| PixelPAlpha | PAlpha | 含預乘 Alpha |
| PixelUndefined | Undefined | 未定義格式 |
PixelFormat32bppPARGB (預乘 Alpha,效能最佳)PixelFormat64bppARGBPixelFormat16bppRGB565 或 PixelFormat8bppIndexedPixelFormat1bppIndexed正確選擇 PixelFormat 可大幅降低記憶體頻寬與提升繪圖效能。