Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This has intrigued me for quite some time.

Does anyone know the algorithm Windows 7 Aero uses to determine the colour to use as the hot-tracking hover highlight on taskbar buttons for currently-running apps?

Windows 7 taskbar hover colours

It is definitely based on the icon of the app, but I can't see a specific pattern of where it's getting the colour value from.

It doesn't seem to be any of the following:

  1. An average colour value from the entire icon, otherwise you would get brown all the time with multi-coloured icons like Chrome.
  2. The colour used the most in the image, otherwise you'd get yellow for the SQL Server Management Studio icon (6th from left). Also, the Chrome icon used red, green and yellow in equal measure.
  3. A colour located at certain pixel coordinates within the icon, because Chrome is red -indicating the top of the icon - and Notepad++ (2nd from right) is green - indicating the bottom of the icon.

I asked this question on ux.stackoverflow.com and it got closed as off-topic, but someone answered with the following:

As described by Raymond Chen in this MSDN blog article:

Some people ask how it's done. It's really nothing special. The code just looks for the predominant color in the icon. (And, since visual designers are sticklers for this sort of thing, black, white, and shades of gray are not considered "colors" for the purpose of this calculation.)

However I wasn't really satisfied with that answer because it doesn't explain how the "predominant" colour is calculated. Surely on the SQL Management Studio icon, the predominant colour, to my eyes at least, is yellow. Yet the highlight is green. I want to know, specifically, what the algorithm is.

share|improve this question
An average colour value from the entire icon, otherwise you would get brown all the time. That doesn’t make sense. For example, how would the Skype, command-prompt, or µTorrent icons average out to brown? ಠ_ఠ (The last time I reverse-engineered one of Windows’ color-calculation algorithms, it took several years of on and off attention and a lot of different kinds of work to finally figure it out. It looks like I may end up hacking this one at some point.) –  Synetech Jun 2 '14 at 18:00
@Synetech you're right - I was just thinking about the wide array of icons available and lots of them that contain multiple colours. For example the Chrome icon or the IIS icon contains red, green yellow & blue and green, yellow & blue respectively. I lazily figured these would average out to a murky brown colour, but you're right that it doesn't apply to lots of more-or-less monochrome icons. –  theyetiman Jun 3 '14 at 8:37
The ONT post has a comment which links to a question about Chrome’s version of this and the linked page explains it by examining the Chrome source-code. The explanation (for that at least) isn’t exactly a simple algorithm. –  Synetech Jun 9 '14 at 21:39
@Synetech nice find - now we're getting somewhere. This is along the lines of what I was looking for. Now, if only we could get the Win7 source code... ;) –  theyetiman Jun 10 '14 at 9:15
I'm guessing but, all pixels are in 3-dimensional space (1 value for each color). Divide them in groups/cubes of for example 10x10x10 , so the color RGB(12,56,97) get's in the group/cube (10-20,50-60,90-100). When dividing the pixels over these groups you keep track of which one is the largest. Finally you determine the predominant color by averaging the group with the most pixels. The size of groups is then a trade of in performance/accuracy. –  mxt3 Sep 17 '14 at 10:44

2 Answers 2

My guess would be that for each color, starting from the top, you get the R, G, and B values, and from them you take the highest and lowest of the three and compare them. The color with the biggest gap between the highest and lowest would be the brightest color in the image. Now in the case of, say, the Chrome icon, there might be several colors tied for biggest gap, but the red is on the top, so it's encountered first, and thus that's what dominates for that image. (I suppose you could test this by designing your own icon, like rotate the Chrome logo 120 degrees and see if the green or yellow dominates instead.)

share|improve this answer

Here is some VB code that averages the RGB colours of an image:

Function AverageRGB(ByRef P As PictureBox) As Long

Dim Count As Long
Dim Red As Long
Dim Green As Long
Dim Blue As Long
Dim Hexed As String
Dim X As Long
Dim Y As Long
Count = 0

For X = 0 To P.Width Step P.Width \ 32

    For Y = 0 To P.Height Step P.Height \ 32
        Hexed = Right("00000" & Hex(P.Point(X, Y)), 6)
        Red = Red + CLng("&h" & Right(Hexed, 2))
        Green = Green + CLng("&h" & Mid(Hexed, 3, 2))
        Blue = Blue + CLng("&h" & Left(Hexed, 2))
        Count = Count + 1


AverageRGB = RGB(Red \ Count, Green \ Count, Blue \ Count)
End Function

It's not really optimized for use in an OS, but it should give you a basic idea -Source

share|improve this answer
He already explained that it is not a simple/basic average. Run the Chrome icon through the code and you’ll see that for yourself. –  Synetech Jun 2 '14 at 18:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.