As usual - after asking the list I found the solution myself :-)

The Loader class + the loadBytes method.

Cheers


Robin





On 10/12/2008, at 12:22 PM, Robin Burrer wrote:

Hi there,

This must be really simple but I just can't find the solution...

How do I decode a jpeg-encoded byte array so that I can draw/display an image from it?


The set pixels method obviously only works for raw image byte arrays.


                private function doEncodingAndDecoding():void
                {
                        
                        
                        var originalBitMap:Bitmap = Bitmap(image1.content);
                        
                        var encoder:JPEGEncoder = new JPEGEncoder();
                        
var myCompressedByteArray:ByteArray = encoder.encode(originalBitMap.bitmapData);
                        myCompressedByteArray.position = 0;
                        
                        
                        
var newBitmapData:BitmapData = new BitmapData(image1.content.width, image1.content.height);
                        var myRect:Rectangle = newBitmapData.rect;
                        
                        
                        //  :-(
                        newBitmapData.setPixels(myRect,myCompressedByteArray);

                        //
                        
                        var newBitmap:Bitmap = new Bitmap(newBitmapData);
                        
                        image2.source = newBitmap;
                        
                        
                        
                }




Thanks for any input!

Robin

Reply via email to