本文介绍了转换ARBG到RGB与alpha混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 让我们说,我们有一个ARGB颜色:Let's say that we have an ARGB color:Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.在此画在现有颜色的顶部,颜色和谐。因此,当它与白色混合,产生的颜色是 Col​​or.FromARGB(255,162,133,255);When this is painted on top of an existing color, the colors will blend. So when it is blended with white, the resulting color is Color.FromARGB(255, 162, 133, 255);该解决方案应该像这样工作:The solution should work like this:Color blend = Color.White;Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.Color rgb = ToRGB(argb, blend); //Same as Color.FromARGB(255, 162, 133, 255); 什么是 ToRGB 的实施?推荐答案这就是所谓的 alpha混合.It's called alpha blending.In伪码,假设背景色(混合)总是有255阿尔法。还假定alpha为0-255。In psuedocode, assuming the background color (blend) always has 255 alpha. Also assumes alpha is 0-255.alpha=argb.alpha()r = (alpha/255)*argb.r() + (1 - alpha/255)*blend.r()g = (alpha/255)*argb.g() + (1 - alpha/255)*blend.g()b = (alpha/255)*argb.b() + (1 - alpha/255)*blend.b()的注:您可能需要有点(更多)小心浮点/ INT数学和四舍五入问题,这取决于语言。铸造中间体因此的 编辑补充:如果你没有255的阿尔法背景颜色,得到代数很多更加复杂。我以前做过,这是一个有趣的练习留给读者(如果你真的需要知道,问另一个问题:)。If you don't have a background color with an alpha of 255, the algebra gets alot more complicated. I've done it before and it's a fun exercise left to the reader (if you really need to know, ask another question :).换句话说,什么颜色为c融入一些背景相同的调合,再混合B.这是有点像计算A + B(这是不一样的B + A)。In other words, what color C blends into some background the same as blending A, then blending B. This is sort of like calculating A+B (which isn't the same as B+A). 这篇关于转换ARBG到RGB与alpha混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-04 23:09