Link to home
Start Free TrialLog in
Avatar of zitt
zitt

asked on

D3: Most Popular color in a BMP

I tried searching the WWW for this... but I wasn't sucessful in finding anything useful.

Given that I have a BMP loaded in a TCanvas... How would I determine (in Pascal) the most popular color?

Basicly, Given an unknown BMP I have already loaded on the background of a Form - I want to extract the most popular color from that Background BMP and set my label backgrounds to the that color. Then somehow "invert" the color to set the font's color.

So, the requirements are:
1) In Pascal puesdo-code.
2) Determine the most popular color.
3) invert that color.

Ideas? Comments?
John
Avatar of RBertora
RBertora
Flag of United Kingdom of Great Britain and Northern Ireland image

Following...
Avatar of edey
edey

what is the bmp's bitdepth? for 256- images, you could simply set up a list, iterate through all the pixels & count the palette ref's.  For small bmp of hifger bit depths I would recomend trying to iterate through all the pixels, but use an accumulator to find the ave. rgb values (or an average of the squares).  If using large true color images, you may want to subdivide the bmp, find the most common color in the sub-regions.

GL
Mike
Avatar of zitt

ASKER

I can't make an assumption about the color depth as the BMP is loaded by the user of the application.
ASKER CERTIFIED SOLUTION
Avatar of edey
edey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial