首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi GDI+ 學習筆記 (28):PixelFormat 像素格式完整對照表

     編輯:Delphi

指定位圖色彩深度:1bpp 至 64bpp、Alpha、預乘、索引色、灰階

PixelFormat 列舉定義每像素位元組織。建立 TGPBitmap 時指定格式,決定色彩精度、記憶體佔用、Alpha 支援。本文列出所有 24 種格式常數、Delphi/微軟名稱對照與中文說明。

範例:32bpp ARGB vs 1bpp Indexed


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;

完整 PixelFormat 對照表

Delphi 常數微軟名稱說明
PixelFormat1bppIndexedFormat1bppIndexed1 位元/像素,索引色 (2 色)
PixelFormat4bppIndexedFormat4bppIndexed4 位元/像素,索引色 (16 色)
PixelFormat8bppIndexedFormat8bppIndexed8 位元/像素,索引色 (256 色)
PixelFormat16bppGrayScaleFormat16bppGrayScale16 位元灰階 (65536 階)
PixelFormat16bppRGB555Format16bppRgb55516 位元,R5G5B5 (保留 1 位)
PixelFormat16bppRGB565Format16bppRgb56516 位元,R5G6B5
PixelFormat16bppARGB1555Format16bppArgb155516 位元,A1R5G5B5
PixelFormat24bppRGBFormat24bppRgb24 位元,R8G8B8
PixelFormat32bppRGBFormat32bppRgb32 位元,R8G8B8 (保留 8 位)
PixelFormat32bppARGBFormat32bppArgb32 位元,A8R8G8B8 (標準)
PixelFormat32bppPARGBFormat32bppPArgb32 位元,預乘 Alpha
PixelFormat48bppRGBFormat48bppRgb48 位元,R16G16B16
PixelFormat64bppARGBFormat64bppArgb64 位元,A16R16G16B16
PixelFormat64bppPARGBFormat64bppPArgb64 位元,預乘 Alpha
PixelAlphaAlpha像素資料含未預乘 Alpha
PixelCanonicalCanonical標準格式 (32bpp ARGB)
PixelDontCareDontCare未指定格式
PixelExtendedExtended保留
PixelGdiGdiGDI 相容色彩
PixelIndexedIndexed索引色模式
PixelMaxMax列舉最大值
PixelPAlphaPAlpha含預乘 Alpha
PixelUndefinedUndefined未定義格式

選擇建議

  • 一般 UI、影像處理:PixelFormat32bppPARGB (預乘 Alpha,效能最佳)
  • 需高色彩精度 (HDR、列印):PixelFormat64bppARGB
  • 記憶體受限、簡單圖示:PixelFormat16bppRGB565 或 PixelFormat8bppIndexed
  • 單色遮罩:PixelFormat1bppIndexed

正確選擇 PixelFormat 可大幅降低記憶體頻寬與提升繪圖效能。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved