ImageEn, unit imageenproc |
|
TImageEnProc.CalcImagePalette
Declaration
function CalcImagePalette(var Palette: array of TRGB; MaxCol: Integer): Integer;
Description
Fills the Palette array with the colors found in the current image.
Palette is the array to fill.
MaxCol is the size of Palette. If the image has more than MaxCol colors, the image is quantized to match the number of colors specified.
Result is the number of colors found (<= MaxCol) or -1 for an error
Note:
◼Will process either the whole image or a rectangular selection. Other selection types are ignored
◼If the image
PixelFormat is not ie24RGB, it will be converted
◼If the image contains more colors than MaxCol, a quantizer is used to reduce the number of colors (using the method specified by
ColorReductionAlgorithm)
◼If the image contains less colors than MaxCol, the result will return the number of colors
◼You can output the palette as an image using
IEDrawColorPalette, or show the palette to the user using
IEPromptForColor
◼To return a list of the most common colors in an image, use
GetDominantColor
| Demos\ImageEditing\CompleteEditor\PhotoEn.dpr |
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |

// Output 256 colors of the image
var
MyColorMap256: array [0..255] of TRGB;
bmp: TIEBitmap;
begin
ImageEnView1.Proc.CalcImagePalette( MyColorMap256, 256 );
bmp := TIEBitmap.Create();
IEDrawColorPalette( bmp, MyColorMap256, 30, 30, 16 );
bmp.SaveToFile( 'D:\Palette256.png' );
bmp.Free;
end;

// Show 1000 colors of the image
const
COLOR_COUNT = 1000;
var
colorMap: array[0..COLOR_COUNT-1] of TRGB;
aColor: TColor;
c: Integer;
begin
c := ImageEnView1.Proc.CalcImagePalette( colorMap, COLOR_COUNT );
IEPromptForColor( aColor, colorMap, c );
end;
See Also
◼CreateRGB
◼TRGB2TColor
◼TColor2TRGB
◼IEDrawColorPalette
◼IEPromptForColor