How to convert a 24-bit RGB color to a 16-bit RGB color

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.