Actionscript 3.0 将 HEX 转换为 ARGB

发布于 2024-08-23 13:55:47 字数 158 浏览 11 评论 0原文

我正在研究 getPixel32() 以及位图和位图数据类。基本上,我想知道如何从十六进制值输出 ARGB 的简单跟踪。

顺便说一句,我的印象是,十六进制值不能产生与 RGBA 值一样多的颜色,我认为/希望这是错误的。也许“网络安全”让我无法理解使用十六进制值生成的颜色的有用性或愿望。

i'm studying getPixel32() and the Bitmap and Bitmap Data classes. Basically, i'd like to know how to output a simple trace of an ARGB from a hexadecimal value.

as an aside, i'm under the impression, which i assume/hope is wrong, that hexadecimal values can't produce as many colors as RGBA values. perhaps "web safe" has thrown me off with understanding the usefulness or desire to use colors produces with hexadecimal values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裂开嘴轻声笑有多痛 2024-08-30 13:55:47

要提取颜色信息,您必须使用按位运算符。颜色的存储方式类似于 0xAARRGGBB,因此您必须提取这些部分。这个小片段应该可以完成这项工作:

var hex: uint = 0x00ff00ff;
var a: int = (hex >>> 0x18) & 0xff;
var r: int = (hex >>> 0x10) & 0xff;
var g: int = (hex >>> 0x08) & 0xff;
var b: int = hex & 0xff;

trace(a, r, g, b);

根据您指定 RGBA 值的方式,答案可能会改变。如果使用每个通道由一个字节指定的 RGBA 值,则可以表达与十六进制值完全相同的颜色。您的“十六进制值”是一个由 4 个字节组成的无符号整数。 Flash 中还有 Number 类型,它由 64 位组成,因此每个通道将表示为 8 个字节而不是 1 个字节。你可以想象你的精确度要高得多。但是,您的屏幕可能设置为“真彩色(32 位)”,并且无法显示那么多颜色。您甚至可以超越双精度(64 位)并使用小数精度,这主要用于金融计算。每个值由 128 位组成,每个通道有 16 个字节。这是使用十六进制表示时的 16 倍。当然,这要精确得多,但您的显示器将无法处理它。

附注。您的图像大小也是宽度高度通道*(每个通道的字节数)。因此,如果每个通道使用一个字节(即 8 位),您就已经获得了足够的颜色。对于大图像,如果每个通道从 8 位变为 32 位,则差异相当大。

具有 8 位精度的 1024x768 图像在内存中为 3072kb,而相同的 32 位图像为 12288kb。使用 Flash 的 Number 类型,相同的图像将占用 24576kb。因此,您可能最好保持 8 位精度,这在大多数情况下应该足够了。

我希望这对您有所帮助,并且您现在对图像及其结构有了更好的理解。

To extract the color information you have to work with bitwise operators. Colors are stored like 0xAARRGGBB so you have to extract those parts. The little snippet should do the job:

var hex: uint = 0x00ff00ff;
var a: int = (hex >>> 0x18) & 0xff;
var r: int = (hex >>> 0x10) & 0xff;
var g: int = (hex >>> 0x08) & 0xff;
var b: int = hex & 0xff;

trace(a, r, g, b);

Depending on how you specify RGBA values the answer might change. If you use RGBA values where each channel is specified by one byte, you can express exactly as much colors as in a hex value. Your "hex value" is an unsigned integer consisting of 4 bytes. In Flash there is also the Number type which consitsts of 64-bit so each channel would be expressed a 8-bytes instead of one. You can imagine that you have much more precision. However, probably your screen is set to "True Color (32-bit)" and will not be able to show that many colors. You go even beyond double-precision (64bit) and use decimal precision, which is mostly used for financial calculations. Each value consists of 128-bit which makes 16 bytes for each channel. That is 16 times more then when using your hex representation. Of course that is much more precision but your monitor will not be able to handle it.

A side note. Your image size is also widthheightchannels*(bytes per channel). So if you use one byte per channel which is 8-bit you get already enough colors. For a big image the difference is quite big if you go from 8-bit to 32-bit per channel.

A 1024x768 image with 8-bit precision is 3072kb whereas the same 32-bit image is 12288kb in memory. That same image would take up 24576kb using Flash's Number type. So you are probably better of staying with 8-bit precision which should be enough in most cases.

I hope that helps and you have a better understanding now of images and their structure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文