distance between two color - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

distance between two color

Demo Code


//package com.java2s;
import java.awt.Color;

public class Main {
    public static double distance(final Color a, final Color b) {
        final int dr = a.getRed() - b.getRed();
        final int dg = a.getGreen() - b.getGreen();
        final int db = a.getBlue() - b.getBlue();
        final int da = a.getAlpha() - b.getAlpha();
        return Math.sqrt(dr * dr + dg * dg + db * db + da * da);
    }//  ww  w.j ava2s.  c o  m
}

Related Tutorials