How do I create an image from an array of pixels? (Flash, ActionScript 3)
I have a Width and Height parameter. I got a lot of colors in this format: [r, g, b, a, r, g, b, a, r, g, b, a ... etc.] The data can be perceived 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 draw this data over some sprite. How to do it?
BTW: I am using Flash Builder for mxml + actioncript encoding. Therefore, if this is easy for you, you can give an example using MXML (not todraw to some sprite, but to some MXML component).
a source to share
I'm not sure why you would like to do this in MXML, you are probably better off coding this in AS3, relying on a sprite and then add the sprite as a child to the MXML component.
Try using a class BitmapData
, it has a method setPixel()
that allows you to set RGBA values.
a source to share