Color to Byte - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Color to Byte

Demo Code


//package com.java2s;

public class Main {
    public static byte toByte(java.awt.Color color) {
        int red = color.getRed();
        int green = color.getGreen();
        int blue = color.getBlue();

        return (byte) (((int) Math.round(red / 255.0 * 7.0) << 5)
                | ((int) Math.round(green / 255.0 * 7.0) << 2) | ((int) Math
                    .round(blue / 255.0 * 3.0)));
    }/*  w  ww.j av  a2 s. c om*/
}

Related Tutorials