Convert [Embed] Image to ByteArray

I was searching for a way to convert a local image, which was saved in my “assets”-Folder to  ByteArray.

Why did I need this? Well – I had got a model, which saved images as ByteArrays (so I could update it with the FileReference-Class easily), but wanted to set a default image into the mode.

public class MyModelClass
    private var myImage:Class;

    public var imageToDisplay:ByteArray = new ByteArray();

    public function MyModelClass(){
        var bitmap:Bitmap = new myImage();
        var bitmapData:BitmapData = bitmap.bitmapData;

        var encoder:PNGEncoder = new PNGEncoder();

        imageToDisplay = encoder.encode(bitmapData);


Tags: , , , ,

2 Responses to “Convert [Embed] Image to ByteArray”

  1. Saurabh Seth Says:

    Hi fightermv,

    Can you help me with converting the embedded gif to Byte Array….
    Its Urgent……………………………………….

    Thanks in advance…………….

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: