There are many friends for the first time using 16-bit color display will encounter how to convert 24-bit RGB color to the corresponding 16-bit RGB color problem, through the relevant information, write a translation of the principle of it, I hope it will be helpful to everyone.
We know that 24-bit RGB is made up of 8-bit red, 8-bit green, and 8-bit blue, respectively:
rrrrrrrr GGGGGGGG bbbbbbbb
For example, the 24-bit RGB red representation method is
11111111 00000000 00000000 (hexadecimal representation: 0xFF0000)
The corresponding 16-bit RGB color is made up of 5-bit red, 6-bit green, and 5-bit red:
RRRR R GGG GGG B BBBB
For example, the 16-bit RGB red representation method is
1111 1 the 0 0000 (hexadecimal representation: 0xf800)
Conversion principle:
Just said the red 24-bit RGB is:11111111 00000000 00000000
Converting to 16-bit RGB requires the 8-bit R value to be shifted right 3 bits to 5 bits:11111
The 8-bit G-value shifts 2-bit to 6-bit:000000
8-bit B-value shifts 3-bit to 5-bit:00000
Through this conversion, we finally get the corresponding 16-bit RGB color:RRRR RGGG GGGB BBBB, converted to the corresponding 16 binary is: 0xf800, Then, when we operate the 16-bit color display, we can assign the corresponding 16-digit value to a pixel on the monitor.
The principle of conversion of other colors is also true.
This article is from the "World is the same" blog, please be sure to keep this source http://970076933.blog.51cto.com/9767314/1885622
How to convert a 24-bit RGB color to a 16-bit RGB color