Here you can find the source of toRGB565(Color c)
Parameter | Description |
---|---|
c | the color to convert into a RGB565 color. |
public static short toRGB565(Color c)
//package com.java2s; /**/*from w w w.ja v a2 s . co 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 { /** * Returns a color in the RGB565 format based on a Color instance. * * @param c the color to convert into a RGB565 color. * @return a color in the RGB565 format based on the specified Color. */ public static short toRGB565(Color c) { if (c == null) { return 0; } short rgb = (short) (((c.getRed() & 0xf8) << 8) | ((c.getGreen() & 0xfc) << 3) | (c.getBlue() >> 3)); // 0 is reserved for null -> set green (has highest resolution) to 1 if (rgb == 0) { return 0x20; } // If the color actually was 0x20 then set it to 0x40 (to the nearest green) if (rgb == 0x20) { return 0x40; } return rgb; } }