I've been playing around with the FPImage to try and get some colour reduction (24bit [16.7 Million colors] bitmaps down to 8 bit [256 color] bitmaps and came up with this which seems to work (at least with bitmaps copied from the clipboard)
procedure ReduceBitmapColors(BMPFile:String);
var
SourceBitmap, TargetBitmap: TFPMemoryImage;
FPMedianCutQuantizer : TFPMedianCutQuantizer;
FPPalette : TFPPalette;
FPFloydSteinbergDitherer:TFPFloydSteinbergDitherer;
ImageReader : TFPReaderBMP;
ImageWriter : TFPWriterBMP;
begin
if FileExists(BMPFile) then begin
SourceBitmap := TFPMemoryImage.Create(0,0);
TargetBitmap := TFPMemoryImage.Create(0,0);
ImageReader := TFPReaderBMP.Create;
ImageWriter := TFPWriterBMP.create;
try
SourceBitmap.LoadFromFile(BMPFile);
FPMedianCutQuantizer := TFPMedianCutQuantizer.Create;
FPMedianCutQuantizer.Add(SourceBitmap);
FPPalette := FPMedianCutQuantizer.Quantize;
FPFloydSteinbergDitherer := TFPFloydSteinbergDitherer.Create(FPPalette);
FPFloydSteinbergDitherer.Dither(SourceBitmap, TargetBitmap);
ImageWriter.BitsPerPixel:=8;
TargetBitmap.SaveToFile(BMPFile, ImageWriter);
finally
SourceBitmap.Free;
TargetBitmap.Free;
FPMedianCutQuantizer.Free;
FPFloydSteinbergDitherer.Free;
ImageReader.Free;
ImageWriter.Free;
end;
end;
end;
To be honest not sure why it does work as, in the process of generating the target bitmap other than do some quantization (what I see to be the process of gathering the information needed for the dithering process) the dithering stage doesn't specify a value to dither to (i.e. the amount of colour reduction to be done). The only point at which this is doen is the saving of the filetype but this is effectively after the process has occured.
Nevertheless, Irfanview is reporting an initial 24bit color reduced to 8 bit color without a significant loss in color (yet a relatively significant decrease in filesize to about a third the original - just separate out the source/target filename to compare if required).
Chris