get Inverse Color - Android android.graphics

Android examples for android.graphics:Color

Description

get Inverse Color

Demo Code

public class Main {

  public static int getInverseColor(int color) {
    int grey = 255 - rgb2greyscale(color);
    if (grey < 128) {
      grey = 0;/*from w ww.  j av  a2 s  .  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 Tutorials