Use QColorDialog to return RGB565 value

382 Views Asked by At

I want to return an RGB565 value when a user selects a color from a QColorDialog. I tried to use the conversion method described from the RGB565 Color Picker website but the output of my code does not represent the same value in hex format:

QColor color = QColorDialog::getColor();

uint8_t red = color.red();
uint8_t green = color.green();
uint8_t blue = color.blue();
qDebug("%d red + %d green + %d blue", red, green, blue);

uint16_t Rgb565 = 0;
Rgb565 = (((red & 0xf8)<<8) + ((green & 0xfc)<<3) + (blue>>3));
qDebug() << Rgb565;

For example, if the RGB values were (255, 0, 0), the output is 63488. I was expecting the output to be 0xF800. What am I doing wrong?

0

There are 0 best solutions below