Board index » delphi » Please help me with bitmaps and palettes

Please help me with bitmaps and palettes

I want to convert a large number of bitmaps from 24 bit to 8bit and save tme
back to file.
I've found the TImage.Pixelformat method , but the new palette it creates
is
all wrong . How can I change my palette, or create and use a customized one
 

Re:Please help me with bitmaps and palettes


Jeppe Andreasen schrieb:

Quote
> I want to convert a large number of bitmaps from 24 bit to 8bit and save tme
> back to file.
> I've found the TImage.Pixelformat method , but the new palette it creates
> is
> all wrong . How can I change my palette, or create and use a customized one

The code below, which uses the ColorQuantizationLibrary contained in
Earl F. Glynn's Color Quantization Demo (available from
http://www.efg2.com/Lab/Graphics/Colors/ShowDemoOne.htm), creates a
8-bit bitmap from a 24-bit one:

use
  PaletteLibrary,
  ColorQuantizationLibrary;

function Create8bitFrom24bitBitmap(Source: TBitmap; ColorBits: Integer):
TBitmap;
var
  ColorQuantizer     :  TColorQuantizer;
  RGBQuadArray       :  TRGBQuadArray;
begin
  Result := TBitmap.Create;
  Result.PixelFormat := pf8bit;
  Result.Width := Source.Width;
  Result.Height := Source.Height;
  ColorQuantizer := TColorQuantizer.Create(256, ColorBits);
  try
    ColorQuantizer.ProcessImage(Source.Handle);
    ColorQuantizer.GetColorTable(RGBQuadArray);
    SetDIBColorTable(Result.Canvas.Handle, 0, 256, RGBQuadArray);
    Result.Canvas.Draw(0, 0, Source);
  finally
    ColorQuantizer.Free
  end;
end;

- Robert
--
Robert Ro?mair
http://home.t-online.de/home/Robert.Rossmair/
Programming environment: Delphi 5.01 Professional, WinNT 4.0 SP6

Re:Please help me with bitmaps and palettes


Quote
> function Create8bitFrom24bitBitmap(
>   Source: TBitmap; ColorBits: Integer): TBitmap;

I forgot to tell how to call this function: the "ColorBits" parameter
should be 5 or 6.
For details read the corresponding Microsoft Systems Journal article:

  http://www.microsoft.com/msj/1097/wicked1097.htm

- Robert

Other Threads