Java tutorial
//package com.java2s; /* * Copyright (C) Stichting Akvo (Akvo Foundation) * * This file is part of Akvo Caddisfly. * * Akvo Caddisfly is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Akvo Caddisfly is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Akvo Caddisfly. If not, see <http://www.gnu.org/licenses/>. */ import android.graphics.Color; public class Main { /** * Computes the Euclidean distance between the two colors * * @param color1 the first color * @param color2 the color to compare with * @return the distance between the two colors */ private static double getColorDistanceRgb(int color1, int color2) { double r, g, b; r = Math.pow(Color.red(color2) - Color.red(color1), 2.0); g = Math.pow(Color.green(color2) - Color.green(color1), 2.0); b = Math.pow(Color.blue(color2) - Color.blue(color1), 2.0); return Math.sqrt(b + g + r); } }