六角透明颜色[复制]

本文翻译自:Hex transparency in colors [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

I'm working on implementing a widget transparency option for my app widget although I'm having some trouble getting the hex color values right. 我正在为我的应用程序小部件实现一个小部件透明度选项,尽管我在修复十六进制颜色值时遇到了一些麻烦。 Being completely new to hex color transparency I searched around a bit although I couldn't find a specific answer to my question. 作为十六进制颜色透明度的全新,我搜索了一下,虽然我找不到我的问题的具体答案。

I want to set transparency by hex color so let's say my hex color id "#33b5e5" and I want it to be 50% transparent. 我想用十六进制颜色设置透明度,所以让我说我的十六进制颜色ID“#33b5e5”,我希望它是50%透明。 Then I'll use "#8033b5e5" because 80 is 50%. 然后我会使用“#8033b5e5”,因为80%是50%。

I found a useful chart here: http://www.dtp-aus.com/hexadeci.htm . 我在这里找到了一个有用的图表: http//www.dtp-aus.com/hexadeci.htm With this data I managed to come up with this: 有了这些数据,我设法得到了这个:

0% = #00
10% = #16
20% = #32
30% = #48
40% = #64
50% = #80
60% = #96
70% = #112
80% = #128
90% = #144

Now the issues start appearing when I get higher than 100 in hex. 现在,当我以十六进制高于100时问题开始出现。 Hex color codes can only be 8 symbols long right? 十六进制颜色代码只能长8个符号吗? For example #11233b5e5 (80%) crashes. 例如#11233b5e5(80%)崩溃。

What can I do to enable me to use the higher numbers aswell? 我能做些什么才能让我使用更高的数字呢?


#1楼

参考:https://stackoom.com/question/14VrO/六角透明颜色-复制


#2楼

Color hexadecimal notation is like following: #AARRGGBB 颜色十六进制表示法如下:#AARRGGBB

  • A : alpha 答:阿尔法
  • R : red R:红色
  • G : green G:绿色
  • B : blue B:蓝色

You should first look at how hexadecimal works. 您应该首先看看十六进制是如何工作的。 You can write at most FF. 你最多可以写FF。


#3楼

That chart is not showing percents. 该图表未显示百分比。 "#90" is not "90%". “#90”不是“90%”。 That chart shows the hexadecimal to decimal conversion. 该图表显示十六进制到十进制的转换。 The hex number 90 (typically represented as 0x90) is equivalent to the decimal number 144. 十六进制数90(通常表示为0x90)等于十进制数144。

Hexadecimal numbers are base-16, so each digit is a value between 0 and F. The maximum value for a two byte hex value (such as the transparency of a color) is 0xFF, or 255 in decimal. 十六进制数字是base-16,因此每个数字都是0到F之间的值。双字节十六进制值的最大值(例如颜色的透明度)是0xFF,或十进制的255。 Thus 100% is 0xFF. 因此100%是0xFF。


#4楼

Here's a correct table of percentages to hex values. 这是一个十六进制值百分比的正确表。 Eg for 50% white you'd use #80FFFFFF. 例如50%的白色,你会使用#80FFFFFF。

  • 100% — FF 100% - FF
  • 95% — F2 95% - F2
  • 90% — E6 90% - E6
  • 85% — D9 85% - D9
  • 80% — CC 80% - CC
  • 75% — BF 75% - 高炉
  • 70% — B3 70% - B3
  • 65% — A6 65% - A6
  • 60% — 99 60% - 99
  • 55% — 8C 55% - 8C
  • 50% — 80 50% - 80
  • 45% — 73 45% - 73
  • 40% — 66 40% - 66
  • 35% — 59 35% - 59
  • 30% — 4D 30% - 4D
  • 25% — 40 25% - 40
  • 20% — 33 20% - 33
  • 15% — 26 15% - 26
  • 10% — 1A 10% - 1A
  • 5% — 0D 5% - 0D
  • 0% — 00 0% - 00

( source ) 来源


#5楼

try this on google search (or click here ) 在谷歌搜索上试试这个(或点击这里

255 * .2 to hex

it will generate 0x33 as a result. 结果会产生0x33

However, google does not round off values so you can only use 1-digit multipliers. 但是,谷歌不会舍入值,因此您只能使用1位乘数。 if you want to use say .85, you have to get the rounded-off value of 255 * .85 first, then type (rounded-value here) to hex in google search. 如果你想使用说.85,你必须首先获得255 * .85的(rounded-value here) to hex ,然后在谷歌搜索中输入(rounded-value here) to hex


#6楼

I built this small helper method for an android app, may come of use: 我为Android应用程序构建了这个小帮手方法,可能会有用:

 /**
 * @param originalColor color, without alpha
 * @param alpha         from 0.0 to 1.0
 * @return
 */
public static String addAlpha(String originalColor, double alpha) {
    long alphaFixed = Math.round(alpha * 255);
    String alphaHex = Long.toHexString(alphaFixed);
    if (alphaHex.length() == 1) {
        alphaHex = "0" + alphaHex;
    }
    originalColor = originalColor.replace("#", "#" + alphaHex);


    return originalColor;
}
发布了0 篇原创文章 · 获赞 7 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/asdfgh0077/article/details/105266115