关于位图的像素格式


1、判断位图的像素格式:
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;

 
 
 
 
 

 

 
  

你可能感兴趣的:(关于位图的像素格式)