Actionscript 3.0 颜色插值问题

发布于 2024-08-04 03:05:42 字数 251 浏览 3 评论 0原文

在 Actionscript 3.0 中,Color 类有一个名为 interpolateColor 的方法。这对我来说似乎很奇怪,但该方法采用两个无符号整数作为颜色,而不是两个 Color 实例。此外,它还为结果颜色返回一个无符号整数。无论如何,我在 API 中没有看到任何用于将 Color 转换为无符号整数或简单地在两个 Color 实例之间进行插值的内容。是否可以在两个 Color 实例之间进行插值,而无需自己编写代码将它们转换为无符号整数?

In Actionscript 3.0, the Color class has a method called interpolateColor. It seems strange to me, but the method takes two unsigned integers for the colors as opposed to two instances of Color. Additionally, it returns an unsigned integer for the resultant color. Anyhow, I don't see anything in the API for converting a Color to an unsigned integer or for simply interpolating between two instances of Color. Is it possible to interpolate between two instances of Color without writing the code to convert them to unsigned integers myself?

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

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

发布评论

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

评论(4

风渺 2024-08-11 03:05:42

这有点不方便,但看起来将其转换为数字是唯一的方法。 这里是一篇关于它的帖子,其中包含以下代码:

public static function interpolateColor(fromColor:uint, toColor:uint, progress:Number):uint
{
    var q:Number = 1-progress;
    var fromA:uint = (fromColor >> 24) & 0xFF;
    var fromR:uint = (fromColor >> 16) & 0xFF;
    var fromG:uint = (fromColor >>  8) & 0xFF;
    var fromB:uint =  fromColor        & 0xFF;

    var toA:uint = (toColor >> 24) & 0xFF;
    var toR:uint = (toColor >> 16) & 0xFF;
    var toG:uint = (toColor >>  8) & 0xFF;
    var toB:uint =  toColor        & 0xFF;

    var resultA:uint = fromA*q + toA*progress;
    var resultR:uint = fromR*q + toR*progress;
    var resultG:uint = fromG*q + toG*progress;
    var resultB:uint = fromB*q + toB*progress;
    var resultColor:uint = resultA << 24 | resultR << 16 | resultG << 8 | resultB;
    return resultColor;  
}

That is somewhat inconvenient, but it looks like converting it to a number is the only way. Here is a post about it, with this code:

public static function interpolateColor(fromColor:uint, toColor:uint, progress:Number):uint
{
    var q:Number = 1-progress;
    var fromA:uint = (fromColor >> 24) & 0xFF;
    var fromR:uint = (fromColor >> 16) & 0xFF;
    var fromG:uint = (fromColor >>  8) & 0xFF;
    var fromB:uint =  fromColor        & 0xFF;

    var toA:uint = (toColor >> 24) & 0xFF;
    var toR:uint = (toColor >> 16) & 0xFF;
    var toG:uint = (toColor >>  8) & 0xFF;
    var toB:uint =  toColor        & 0xFF;

    var resultA:uint = fromA*q + toA*progress;
    var resultR:uint = fromR*q + toR*progress;
    var resultG:uint = fromG*q + toG*progress;
    var resultB:uint = fromB*q + toB*progress;
    var resultColor:uint = resultA << 24 | resultR << 16 | resultG << 8 | resultB;
    return resultColor;  
}
萌逼全场 2024-08-11 03:05:42

Flash 播放器中的所有颜色都被视为无符号整数。 Color 类特定于 Flash IDE,并扩展了 ColorTransform。 http://livedocs.adobe.com/flash/ 9.0/ActionScriptLangRefV3/fl/motion/Color.html#propertySummary

因此,在您的情况下,您需要做的就是使用 Color 类的“.color”属性。例如,要获取实际颜色,或者仅使用“interpolateTransform”函数,该函数确实从 ColorTransform 转到 ColorTranform。

All colors in the flash player are treated as an unsigned ints. The Color class is specific to the Flash IDE and extends ColorTransform. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/motion/Color.html#propertySummary

So in your case, all you need to do is use the ".color" property of your Color classes. eg., to get the actual color, or just use the "interpolateTransform" function instead which does go from ColorTransform to ColorTranform.

不知所踪 2024-08-11 03:05:42

也许有点晚了,我只是偶然到达此页面,但是,在调整图像大小时,我遇到了类似的插值颜色问题,最后我发现的最佳解决方案是使用 Bicubic 进行 2D 变换,使用 Hermite 进行 1D 变换。看一下http://www.yoambulante.com/en/labs/interpolation。 php 干杯!

maybe it is a bit late, I just arrived here in this page by chance but, I was facing a similar problem with the interpolation colour when resizing images and at the end the best solution I found was using Bicubic for 2D transformations and Hermite for 1D. take a look on it http://www.yoambulante.com/en/labs/interpolation.php cheers!

丢了幸福的猪 2024-08-11 03:05:42

不能使用 ColorTransform 实例吗?
您从 instanceMovieClip.transform.colorTransorm 获取 colorTransfrom 然后用 Color.interpolateTransform 插入 colorTransofrm ?

我认为我不明白您想要实现的目标(为什么需要插入两个颜色实例?而不是颜色(ints)或 colorTransforms)?

Can you not use ColorTransform instances ?
You get the colorTransfrom from instanceMovieClip.transform.colorTransorm then interpolate the colorTransofrm with Color.interpolateTransform ?

I don't think I understand what you're trying to achieve (why do you need to interpolate two Color Instances ? and not colors(ints) or colorTransforms) ?

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