From: Robert Rossmair Subject: Re: Please help me with bitmaps and palettes Date: 24 Mar 2000 00:00:00 GMT Message-ID: <8bfh1n$cic$1@news01.btx.dtag.de> Content-Transfer-Encoding: 8bit References: X-Posting-Agent: Hamster/1.3.13.0 X-Accept-Language: de,en X-Sender: 340065752685-0001@t-dialin.net Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@t-online.de X-Trace: news01.btx.dtag.de 953894775 12876 340065752685-0001 000324 10:46:15 Organization: - Mime-Version: 1.0 Newsgroups: borland.public.delphi.graphics Jeppe Andreasen schrieb: > 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