get Color Difference - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

get Color Difference

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        int color1 = 2;
        int color2 = 2;
        System.out.println(getColorDifference(color1, color2));
    }/* w w w . j  av a  2s  . co  m*/

    public static int getColorDifference(int color1, int color2) {
        Color color = new Color(color1);
        int red1 = color.getRed();
        int green1 = color.getGreen();
        int blue1 = color.getBlue();

        color = new Color(color2);
        int red2 = color.getRed();
        int green2 = color.getGreen();
        int blue2 = color.getBlue();
        return (Math.max(red1, red2) - Math.min(red1, red2))
                + (Math.max(green1, green2) - Math.min(green1, green2))
                + (Math.max(blue1, blue2) - Math.min(blue1, blue2));
    }
}

Related Tutorials