You are on page 1of 1

public static void main(String[] args) {

// TODO code application logic here


System.out.println(Integer.toHexString(RGB888ToRGB565(0x11ffffff)));
System.out.println(Integer.toHexString(RGB565ToRGB888(RGB888ToRGB565(0xf
feeff))));
}
static int
int B
int G
int R

RGB888ToRGB565(int red, int green, int blue) {


= (blue >>> 3) & 0x001F;
= ((green >>> 2) << 5) & 0x07E0;
= ((red >>> 3) << 11) & 0xF800;

return (R | G | B);
}
static int RGB888ToRGB565(int aPixel) {
//aPixel <<= 8;
//System.out.println(Integer.toHexString(aPixel));
int red = (aPixel >> 16) & 0xFF;
int green = (aPixel >> 8) & 0xFF;
int blue = (aPixel) & 0xFF;
return RGB888ToRGB565(red, green, blue);
}
static int RGB565ToRGB888(int aPixel) {
int b = (((aPixel) & 0x001F) << 3) & 0xFF;
int g = (((aPixel) & 0x07E0) >>> 2) & 0xFF;
int r = (((aPixel) & 0xF800) >>> 8) & 0xFF;
// return RGBA
return 0x000000ff | (r << 24) | (g << 16) | (b << 8);
}

You might also like