• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Wierd one - web color comparison

Hi Experts,

         Ive parsed the style sheet of a web page document and now im examining the document to identify visual segnmentation e.g. two sections with distinctly different background colors. What i need to know is if its possiable to compare two strings that represent color in style sheets i.e. background-color:#333333;

I need a method that gives a quantitive value to show how much the colors differ.

Any help welcomed.

Thanks, Chris.
0
icb01co1
Asked:
icb01co1
1 Solution
 
objectsCommented:
not sure i understand your problem.
Why don't you just parse the value as an integer
0
 
JakobACommented:
Yes and no.  The colorcodes used in RGB colors are not linear with respect to the percieved colors.
So you can compare, but the comparison is not worth much.

the color #334455 should be read as 3 seperate numbers
  int redComponent    = Integer.parseInt( "#334455".substring(1,3), 16 );
  int greenComponent = Integer.parseInt( "#334455".substring(3,5), 16 );
  int blueComponent   = Integer.parseInt( "#334455".substring(5), 16 );

to compare you then calculate the difference individually for each color component:
    int redDifference = Math.abs( redComponent_nr1 - redComponent_nr2 );
    int greenDifference = Math.abs( greenComponent_nr1 - greenComponent_nr2 );
    int blueDifference = Math.abs( blueComponent_nr1 - blueComponent_nr2 );
    int totalDifference = redDifference +greenDifference +blueDifference;

But remember that this difference calculation will not give you quite the differences you intuitively expect. I just hope it may be good enough for your purposes.

regards JakobA
0
 
icb01co1Author Commented:
Pure genius, thankyou very much kind sir.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now