下面有段程序测试通过。
type
TPalette = record
palVersion: Word;
palNumEntries: Word;
palPalEntry: array[0..1] of TPaletteEntry;
end;
var
Res: TBitmap;
Pal: TPalette;
begin
...
Res := TBitmap.Create;
try
Res.Width := Bmp.Width; //Bmp是待转换的位图
Res.Height := Bmp.Height;
Res.PixelFormat := pf1Bit;
Pal.palVersion := $300;
Pal.palNumEntries := 2;
with Pal.palPalEntry[0] do begin
peRed := 0;
peGreen := 0;
peBlue := 0;
peFlags := 0;
end;
with Pal.palPalEntry[1] do begin
peRed := 255;
peGreen := 255;
peBlue := 255;
peFlags := 0;
end;
Res.Palette := CreatePalette(PLogPalette(@Pal)^);
Res.Canvas.Draw(0, 0, Bmp);
Res.SaveToFile(FileName);
finally
Res.Free;
end;
...
end;