Java examples for 2D Graphics:Color RGB
Calculates the Manhattan distance of two colors in the RGB color space (a value in range 0-(255*3)).
/*// w w w .j ava2 s . co m * Copyright 2010 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //package com.java2s; import java.awt.Color; public class Main { /** * Calculates the Manhattan distance of two colors in the RGB color space * (a value in range 0-(255*3)). */ public static int colorDiff(Color color1, Color color2) { return colorDiff(color1.getRed(), color1.getGreen(), color1.getBlue(), color2.getRed(), color2.getGreen(), color2.getBlue()); } /** * Calculates the Manhattan distance of two colors in the RGB color space * (a value in range 0-(255*3)). */ public static int colorDiff(int r1, int g1, int b1, int r2, int g2, int b2) { return Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2); } }