六角透明颜色[复制]

本文翻译自: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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
六角学院是一所为广大学生提供优质教育和培训的机构。学院设立多个专业课程和研究项目,为学生提供知识和技能的综合培训。 作为一所高质量的学府,六角学院以其优秀的师资和先进的教学方法著称,为学生提供最佳的学习体验。学院聘请了许多具有丰富教学经验和专业背景的教授和导师,他们致力于以启发式和实践为基础的教学方法,激发学生的学习兴趣,提高他们的学术能力和职业技能。 六角学院开设了各种各样的课程,包括计算机科学、数据科学、人工智能、软件开发等。每个课程都经过精心设计,结合最新的行业趋势和技术标准,为学生提供高效的学习内容。学院注重实践和项目驱动的学习方式,让学生通过实际操作和实际应用来发展和巩固他们的技能。 在六角学院,我们非常关注学生的个人发展和职业规划。学院提供一系列的职业咨询和指导服务,帮助学生了解不同的职业选择和就业市场的趋势。我们还与各个行业的公司和组织建立了广泛的合作关系,为学生提供实习和就业机会。 六角学院致力于培养优秀的人才,为他们的未来发展打下坚实的基础。我们相信通过知识、技能和实践的结合,学生将能够在各自的领域中取得突破和成功。 如果你希望接受一流的教育和培训,六角学院将是你的最佳选择!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值