如何从像素颜色数组创建图像? (Flash、Actionscript 3)
我有一个宽度和高度参数。我得到了这样格式的颜色数组:[r,g,b,a,r,g,b,a,r,g,b,a...等] 数据可以通过类似这样的方式访问,
for(var y = 0; y < height; y++)
{
for(var x = 0; x < width; x++)
{
r = data[y*width + x + 0]
g = data[y*width + x + 1]
b = data[y*width + x + 2]
a = data[y*width + x + 3]
}
}
我想将这些数据绘制在某个精灵上。这样的事该怎么办呢?
顺便说一句:我使用 Flash Builder 进行 mxml+actionscript 编码。因此,如果对您来说很容易,您可以给出使用 MXML 的示例(不是在某些精灵上绘制,而是在某些 MXML 组件上绘制)。
I have a Width and Height parametr. I have been given an array of colors in such format: [r, g, b, a, r, g, b, a, r, g, b, a... etc]
Data can be acsessed by something like this
for(var y = 0; y < height; y++)
{
for(var x = 0; x < width; x++)
{
r = data[y*width + x + 0]
g = data[y*width + x + 1]
b = data[y*width + x + 2]
a = data[y*width + x + 3]
}
}
I want to paint that data on some sprite. How to do such thing?
BTW: I use Flash Builder for mxml+actionscript coding. So if it is easy for you you can give example using MXML (not todraw on some sprite but on some MXML component).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您为什么要在 MXML 中执行此操作,您最好在 AS3 中进行编码,方法是在精灵上绘图,然后将精灵作为子级添加到 MXML 组件中。
尝试使用
BitmapData
类,它有一个setPixel()
方法,可让您设置 RGBA 值。I'm not sure why you would want to do that in MXML, you're probably better off doing this in coding this in AS3 by drawing on a sprite and then add the sprite as a child to a MXML component.
Try using the
BitmapData
class, it has asetPixel()
method that lets you set RGBA values.