Get color Distance - Android Graphics

Android examples for Graphics:Color Operation

Description

Get color Distance

Demo Code


//package com.java2s;

import android.graphics.Color;

public class Main {
    private static final double colorDistance(int color1, int color2) {
        int redDistance = Color.red(color1) - Color.red(color2);
        int greenDistance = Color.green(color1) - Color.green(color2);
        int blueDistance = Color.blue(color1) - Color.blue(color2);
        double distance = Math.sqrt(redDistance * redDistance
                + greenDistance * greenDistance + blueDistance
                * blueDistance);// w ww.j a v  a 2  s  .  c  om
        return distance / 256.;
    }
}

Related Tutorials