RGB color description and Conversion Algorithm

Source: Internet
Author: User
RGB value conversion
Rbg is often used for image processing. It can be expressed in decimal (0-255) or hexadecimal (00-ff. A pound is equal to or equal to a hexadecimal value.
The decimal number is represented by 0 to 9 digits. The hexadecimal format is represented by a dozen numbers ranging from 0 to 9 plus six Latin letters A, B, C, D, E, and F. That is, a represents ten, and f Represents fifteen. According to this rule, it is easy to convert.
For example, convert decimal 245 to hexadecimal format,
245/16 = 15... remainder 5
Therefore, the decimal 245 is represented in hexadecimal format, that is, F5.
For example, convert the hexadecimal EA to the decimal mode. If e is 14 and A is 10, then
14x16 + 10 = 234.
Therefore, the hexadecimal EA is represented in decimal format, that is, 234.
Of course, it is more convenient to directly use a calculator. Windows has such a calculator. In 'start/Program/attachment.

-------------------------------------

Implementation of hexadecimal numbers in pixels
In most programming languages, even HTML uses the RGB color mode, which combines red, green, and blue into a certain color to form a pixel. In our understanding, an RGB color is 3 bytes, each of which is an integral part of the RGB color. Note: 1 byte = 8 bits, while RGB color is a 24-bit color system. Each byte represents a value ranging from 0 to in decimal number. It is 0-FF in hexadecimal format. In HTML, you can see a tag like this. <font color = "# ff0000">, the value represents red in RGB color. Note that it is represented by six digits. RGB colors cannot be expressed by the length of more than six digits because they only contain three bytes. In the RGB color, "# ff12ac" and the first and second digit "FF" indicate that the pixel is pure red, which is the highest value, because the number of bytes does not exceed the FF value, the next two digits "12" are displayed as a very bright green value, which is quite low. The last two digits are "AC ", this pixel is displayed in blue with a strong brightness, which is relatively high. Finally, the combination color of this pixel is pink.
Note that the vast majority of programming languages, including JavaScript, must be expressed as "0x" in hexadecimal notation, which prevents computers from obfuscation of decimal and hexadecimal notation. Therefore, when using RGB color in Javascript earlier, the above value should be written as 0xff12ac. For example, we can define the background color as the pink color in javascript:
Document. bgcolor = 0xff12ac;
We can adjust the color by combining 256 different shades of the red, green, and blue colors of RGB colors. We can achieve 0.16 million colors!
Color gradient
Now that we understand how colors and pixels work, we need to answer the correct question. How can we achieve the gradient of inverted characters?
Gradient refers to two different colors, respectively as the starting color and ending color, to find out how many steps they need to change the color increment from the starting color to the final color. It can be expressed using the following formula:
(Secondcolor-firstcolor)/number_of_steps;
"Secondcolor" indicates the final color, and "firstcolor" indicates the starting color. The variable "number_of_steps" refers to the length of the character to be gradient. We use this variable to determine how many incremental changes each character in the pixel has. If we can know the increment between characters, the following statements are what we need:
(Secondcolor-firstcolor)/string. length;
Start gradient
Although the above concept is very simple, we need to use it in practice. We need to implement gradient in various colors composed of red, green, and blue. If we only subtract red and blue and use some values to divide them, then the color gradient does not work correctly according to the chromatographic physical principle. We need some pretty transitional results. Then, we must split the three primary colors from the RGB colors: Red, green, and blue, and separately calculate a certain dominant color.
You may wonder how you do it! This includes a more advanced method-Bit Blocking. Blocks remove some color blocks that we no longer need.

---------------------------------------------------

All of the above are quotes. Enter the corresponding values for calculation:

HEX ):
Decimal (DEC ):
Percentage (PER ):

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.