Here you can find the source of toByte(int rgb)
public static byte toByte(int rgb)
//package com.java2s; //License from project: Apache License public class Main { public static byte toByte(int rgb) { int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = (rgb >> 0) & 0xff; float brightness = getBrightness(r, g, b); return (byte) (brightness * 255f); }/*from w w w.j a v a2 s . c om*/ public static float getBrightness(float r, float g, float b) { r /= 255f; g /= 255f; b /= 255f; return (r + g + b) / 3.0f; } }