var colorCount: array[TColor] of integer; ... for x... for y... inc(colorCount[bitmap.canvas.pixels[x, y]]);