Aur
Aur

Reputation: 17

How to convert Image to ByteArray in Flex 4

I would like to write an image in pdf. I use AlivePDF and the method is pdf.addImageStream(image,...). The image is a ByteAray and I do not know how to convert my Image object in an ByteArray. I would appreciate if you can give me a suggestion.

Upvotes: 1

Views: 1418

Answers (1)

jason
jason

Reputation: 1631

1.load the image:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, beginDraw);
loader.load(new URLRequest(imgURL));

2.get the bitmapData and convert to ByteArray:

private function beginDraw(event:Event):void{
    var bitmap:Bitmap = loader.content as Bitmap;
    var rect:Rectangle = new Rectangle(0,0,bitmap.width. bitmap.height);
    var result:ByteArray = bitmap.bitmapData.getPixels(rect);
}

Upvotes: 3

Related Questions