Java Color Create toColor(short rgb565)

Here you can find the source of toColor(short rgb565)

Description

Return a Color based on a color in RGB565 format.

License

Open Source License

Parameter

Parameter Description
rgb565 the color in RGB565 format.

Return

a Color based on the specifed color in RGB565 format.

Declaration

public static Color toColor(short rgb565) 

Method Source Code

//package com.java2s;
/**//w  ww.ja  va  2 s.  c o m
 * Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://robocode.sourceforge.net/license/epl-v10.html
 */

import java.awt.*;

public class Main {
    /**
     * Return a Color based on a color in RGB565 format.
     *
     * @param rgb565 the color in RGB565 format.
     * @return a Color based on the specifed color in RGB565 format.
     */
    public static Color toColor(short rgb565) {
        if (rgb565 == 0) {
            return null;
        }
        if (rgb565 == 0x20) {
            return Color.BLACK;
        }
        return new Color(255 * ((rgb565 & 0xF800) >> 11) / 31, 255 * ((rgb565 & 0x07e0) >> 5) / 63,
                255 * (rgb565 & 0x001f) / 31);
    }
}

Related

  1. toColor(final String text, final Color defaultValue)
  2. toColor(float[] color)
  3. toColor(int rgba)
  4. toColor(int x)
  5. toColor(Node n)
  6. toColor(String background)
  7. toColor(String hexString)
  8. toColor(String pString)
  9. toColor(String str)