Android Color Adjust getInverseColor(int color)

Here you can find the source of getInverseColor(int color)

Description

get Inverse Color

Declaration

public static int getInverseColor(int color) 

Method Source Code

//package com.java2s;

public class Main {
    public static int getInverseColor(int color) {
        int grey = 255 - rgb2greyscale(color);
        if (grey < 128) {
            grey = 0;// www.  j av a2s  .c o m
        } else {
            grey = 255;
        }
        return (grey << 16) + (grey << 8) + grey;
    }

    public static int rgb2greyscale(int color) {
        if (color > 256 * 256 * 256) {
            color = color % (256 * 256 * 256);
        }
        int r = color / 256 / 256;
        int g = (color - r * 256 * 256) / 256;
        int b = color - r * 256 * 256 - g * 256;
        return (int) (0.299 * r + 0.587 * g + 0.114 * b);
    }
}

Related

  1. adjustTextColor(int color)