1、判斷位圖的像素格式:
2、位圖的像素格式轉換:
3、按指定的像素格式保存位圖:
var bit: TBitmap; pix: TPixelFormat; s: string; begin bit := TBitmap.Create; bit.LoadFromFile('c:\temp\test.bmp'); //位圖路徑 pix := bit.PixelFormat; s := ''; case pix of pfDevice: s := 'Device'; {設備支持的像素格式} pf1bit: s := '1bit'; pf4bit: s := '4bit'; pf8bit: s := '8bit'; pf15bit: s := '15bit'; pf16bit: s := '16bit'; pf24bit: s := '24bit'; pf32bit: s := '32bit'; pfCustom: s := 'Custom'; {其他格式} end; ShowMessage(s); bit.Free; end;
2、位圖的像素格式轉換:
var bit: TBitmap; begin bit := TBitmap.Create; bit.LoadFromFile('c:\temp\test.bmp'); bit.PixelFormat := pf4bit; bit.SaveToFile('c:\temp\test2.bmp'); bit.Free; end;
3、按指定的像素格式保存位圖:
var bit: TBitmap; begin bit := Self.GetFormImage; //把窗體客戶區獲取為圖像, 無須 bit := TBitmap.Create; bit.PixelFormat := pf1bit; bit.SaveToFile('c:\temp\test.bmp'); bit.Free; //但要釋放 end;