Table of Contents
回复内容:
Home Web Front-end H5 Tutorial 电子行业中,以0x开头颜色表示法和以#开头的颜色表示法有什么区别?

电子行业中,以0x开头颜色表示法和以#开头的颜色表示法有什么区别?

Jun 07, 2016 am 08:45 AM
google rgb

最近遇到一些特殊的情况。我发现rgb颜色除了以#开头表示以外,还有以0x开头表示的。但是Google和百度上都找不到相关的介绍。不知道有没有从事相关研究的大哥仔细讲解两者之间的区别?

回复内容:

长懒看的请看最后一段结论。

从计算机的数值表示上讲,0x开头的其实并不是所谓颜色代码的表示方法,而是16进制数的标准写法。譬如0xA就是十进制的10。
而#开头的六(或三)位十六进制数是在设计领域(如CSS以及一些绘图软件)中颜色代码的表示方法。

如果我们只考虑24位颜色的话,电脑中每个像素的颜色其实就是用3个字节(24位)的无符号整数来存储的。所以用0x开头的“颜色代码”,也就是这个十六进制数表示的数值,其实就是颜色在内存(显存)中的存储方式。
为什么不采用我们常见的10进制数而要采用0x开头的16进制数来表示颜色呢?因为在颜色这3个字节中,大家规定17-24位表示红色的分量,9-16位表示绿色的分量,1-8位表示蓝色的分量,因此一个十进制数16777215表示的颜色虽然很难给我们一个直观的感觉,而将它转换成16进制数0xFFFFFF我们就可以很轻易的看出前两位FF表示红色,中间两位FF表示绿色,后面两位FF表示蓝色。这个数值表示白色。
于是就出现了阁下熟悉的在设计领域我们就使用#开头的6位十六进制数来表示颜色的方式,这样一来,既直观又可以方便地在内存中进行转换与存储。
所以我们说#开头的六位十六进制数仅仅表示颜色,0x开头的数字表示包括颜色在内的一般数值

于是我们就可以阐述出它们的区别:
我们知道,在十进制中0123和123是相等的两个数字,所以0x000FFF和0xFFF是相等的两个数值,也就表示相同的两个颜色。但是#000FFF和#FFF表示的却是两个不同的颜色。在CSS(以及部分绘图软件中)#后面跟3个十六进制数是被允许的,比如#ABC表示的颜色和#AABBCC表示的颜色相同。但是跟1、2、4、5个十六进制数仍然是非法的颜色代码。所以#000FFF表示蓝色掺了一点绿,#FFF即#FFFFFF表示白色,#0FFF什么都不表示,是非法的颜色代码。 楼主所说的颜色空间是RGB空间,这个颜色空间能够表示绝大多数肉眼可见的颜色。但是缺点是不好量化,因为其将色调、亮度、饱和度融在一块了。
除此之外的颜色空间还有:CMYK(青、洋红、黄、黑,用于墨盒中)、HSI(色调、饱和度、强度,用于数字化处理颜色)等。
颜色值一共6位,以16进制表示,前两位表示红色值,中间两位表示绿色值,最后两位表示蓝色值。 0xAARRGGBB
#RRGGBB
rgba(r,g,b,a) --- (00xefeff4
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Jun 22, 2024 am 10:50 AM

Currently, four new Pixel smartphones are anticipated to land this autumn. To recap, the series is rumoured to feature thePixel 9 and Pixel 9 Pro at launch. However, the Pixel 9 Pro will be a rival to the iPhone 16 Pro rather than a Pixel 8 Pro (curr

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI has started to provide developers with access to extended context windows and cost-saving features, starting with the Gemini 1.5 Pro large language model (LLM). Previously available through a waitlist, the full 2 million token context windo

Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Jul 30, 2024 pm 01:06 PM

Google's AI assistant, Gemini, is set to become even more capable, if the APK teardown of the latest update (v15.29.34.29 beta) is to be considered. The tech behemoth's new AI assistant could reportedly get several new extensions. These extensions wi

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Aug 24, 2024 am 06:43 AM

Google recently responded to the performance concerns about the Tensor G4 of the Pixel 9 line. The company said that the SoC wasn't designed to beat benchmarks. Instead, the team focused on making it perform well in the areas where Google wants the c

Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Aug 01, 2024 pm 02:56 PM

The Pixel 9 series is almost here, having been scheduled for an August 13 release. Based on recent rumours, the Pixel 9, Pixel 9 Pro and Pixel 9 Pro XL will mirror the Pixel 8 and Pixel 8 Pro (curr. $749 on Amazon) by starting with 128 GB of storage.

Google Pixel 9 Pro XL gets tested with desktop mode Google Pixel 9 Pro XL gets tested with desktop mode Aug 29, 2024 pm 01:09 PM

Google has introduced DisplayPort Alternate Mode with the Pixel 8 series, and it's present on the newly launched Pixel 9 lineup. While it's mainly there to let you mirror the smartphone display with a connected screen, you can also use it for desktop

New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative Aug 08, 2024 pm 03:05 PM

A few months have passed since Android Authority demonstrated a new Android desktop mode that Google had hidden away within Android 14 QPR3 Beta 2.1. Arriving hot on the heels of Google adding DisplayPort Alt Mode support for the Pixel 8 and Pixel 8

Google opens AI Test Kitchen & Imagen 3 to most users Google opens AI Test Kitchen & Imagen 3 to most users Sep 12, 2024 pm 12:17 PM

Google's AI Test Kitchen, which includes a suite of AI design tools for users to play with, has now opened up to users in well over 100 countries worldwide. This move marks the first time that many around the world will be able to use Imagen 3, Googl

See all articles