views:

1280

answers:

2
    var myFile:File = new File("./test.jpg");
    var myFileStream1:FileStream = new FileStream();
    myFileStream1.open(myFile, FileMode.READ);
                                    var byte:ByteArray = new ByteArray();  
                                myFileStream1.readBytes(byte,0,byte.bytesAvailable);
    myFileStream1.close();

now how can i add byte variable to the canvas ? for example var canvas:Canvas = new Canvas(); canvas.addChild(byte); is it possible to add ByteArray to the canvas?

A: 

No, you cannot. It is because ByteArray itself cannot be displayed since the Flash Player do not know what it is.

In your case you are going to display the "test.jpg" image on a Canvas, right? You may simply set Image control's source property to the loaded ByteArray object and add it to the Canvas. See http://livedocs.adobe.com/flex/3/langref/mx/controls/Image.html

Andy Li
Well, your (msaif) solution definitely will do the job. But it actually IS what will be done in `Image` control internally. If you are using Flex framework, why avoid using `Image` control when its code is shorter comparing to using `Loader` + `BitmapData` + `Bitmap` + `UIComponent`?
Andy Li
A: 

I sloved this without Image control I used decoder concept.Here is the below: It worked.

loader.loadBytes(eizo.idolImage);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    function (e:Event):void {
    var bmpData:BitmapData = new BitmapData(loader.width, loader.height);
    bmpData.draw(loader);
    var ui:UIComponent = new UIComponent();
    ui.addChild(new Bitmap(bmpData));
    canvas0.addChild(ui);
    }
);