【问题标题】:Multiply alpha channel in an AARRGGBB color在 AARRGGBB 颜色中乘以 Alpha 通道
【发布时间】:2013-07-05 06:51:20
【问题描述】:

我有一个 AARRGGBB 值,用于填充网格中的单元格,我在尝试使用照明引擎时使用该值:

var color:Number = 0xFF000000; // Full opaque black.

有些光源具有半径参数。距离是从光源单元到该半径内的附近单元测量的。然后为每个附近的单元格赋予一个百分比值,即:

distanceFromSource / sourceRadius

因此,较高的百分比表示离源较远的单元格。

我想将上面颜色的 alpha 通道乘以百分比,然后用结果值填充单元格。基本上我希望 AARRGGBB 值的 AA 介于 0-100% 之间。当我尝试做直接乘法时,我得到了奇怪的结果:

我相信我需要为此使用特殊运算符,以及 BitmapDataChannel 中看到的值。不幸的是,这就是我卡住的地方。

如何将 AARRGGBB 颜色中的 Alpha 通道乘以百分比?

【问题讨论】:

    标签: actionscript-3 actionscript colors bitmap rendering


    【解决方案1】:

    您需要保留像素的 rgb 值。只乘以 uint 的 alpha 字节。

    function multiplyAlpha(color:uint, percent:Number):uint
    {
      //returns the pixel with it's aplha value multiplied by percent
      //percent is expected to be in the range 0..1
      var a:uint = (color >> 24) * percent;
      var rgb:uint = color & 0x00ffffff;
      return ((a<<24) | rgb);
    }
    
    function setAlphaByPercent(color:uint, percent:Number):uint
    {
      //returns the pixel with it's a new alpha value based on percent
      //percent is expected to be in the range 0..1
      var a:uint = 0xff * percent;
      var rgb:uint = color & 0x00ffffff;
      return ((a<<24) | rgb);
    }
    

    【讨论】:

    猜你喜欢
    • 2011-06-11
    • 2011-08-02
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 2011-06-30
    • 2016-12-28
    相关资源
    最近更新 更多