如何从像素颜色数组创建图像? (Flash、Actionscript 3)

发布于 2024-08-29 04:27:45 字数 473 浏览 14 评论 0原文

我有一个宽度和高度参数。我得到了这样格式的颜色数组:[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 技术交流群。

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

发布评论

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

评论(1

香橙ぽ 2024-09-05 04:27:45

我不确定您为什么要在 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 a setPixel() method that lets you set RGBA values.

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