Java RGB Color Convert To convertRgb888To565(int rgb888)

Here you can find the source of convertRgb888To565(int rgb888)

Description

Converts an RGB 888 color to RGB 565 color space.

License

Open Source License

Parameter

Parameter Description
rgb888 The RGB 888 color value

Return

The RGB 565 color

Declaration


public static int convertRgb888To565(int rgb888) 

Method Source Code

//package com.java2s;
/*//from   ww w  .  java  2s  . c o  m
 * Copyright (C) 2006-2012 Klaus Reimer <k@ailis.de>
 * 
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by the 
 * Free Software Foundation; either version 2.1 of the License, or (at your 
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this program; if not, write to the Free Software Foundation, 
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

public class Main {
    /**
     * Converts an RGB 888 color to RGB 565 color space. Alpha values will get
     * lost.
     * 
     * @param rgb888
     *            The RGB 888 color value
     * @return The RGB 565 color
     */

    public static int convertRgb888To565(int rgb888) {
        return ((rgb888 & 0xf80000) >> 8) | ((rgb888 & 0xfc00) >> 5) | ((rgb888 & 0xf8) >> 3);
    }

    /**
     * Converts an RGB 888 color array to an RGB 565 color array. Alpha values
     * will get lost.
     * 
     * @param rgb888
     *            The RGB 888 color array
     * @return The RGB 565 color array
     */

    public static int[] convertRgb888To565(int[] rgb888) {
        int max;
        int[] rgb565;

        max = rgb888.length;
        rgb565 = new int[max];
        for (int i = 0; i < max; i++) {
            rgb565[i] = convertRgb888To565(rgb888[i]);
        }
        return rgb565;
    }
}

Related

  1. convertRgbaToArgb(int rgba)
  2. convertRgbToByteArray(int[] rgb)
  3. convertRGBtoHSL(int r, int g, int b)
  4. convertRGBtoHSV(float[] rgb, float[] hsv)