1 Reply Latest reply on Feb 6, 2010 10:58 PM by Flex harUI

    Why does LoaderInfo.bytes.bytesAvailable differ from bytesTotal ?

    ZeDav

      Before I give a code snippet, let me explain what I'm trying to do.

       

      I'm trying to load an image from an arbitrary URL (user given), that can be any of jpeg, gif, png.

      What I want is the compressed version of the image, not the bitmap. My goal is transmit it to my database in compressed form.

       

      So with that in mind:

      1. I first tried to use URLLoader

        => It returns the correct byteArray of the image but not the contentType (e.g. image/jpeg etc...)

      2. Then I tried to use Loader

      => This returns both the contentType and the byteArray of the data, however the byteArray is not the same size as the image, there are some extra bytes. That's where loaderInfo.bytes.bytesAvailable differs from lodareInfo.bytesTotal.

       

      Code snippet:


              private function onWebloadURL(url:String):void {

                  var imageUrl:URLRequest = new URLRequest(url);
                  var imageLoad:Loader = new Loader();
                  imageLoad.contentLoaderInfo.addEventListener(Event.COMPLETE,OnWebloadURLLoaded);
                  imageLoad.load(imageUrl);           

              }

              private function OnWebloadURLLoaded(event:Event):void {

                  // Here event.currentTarget.bytes contains some extra data

                  // and currentTarget.bytes.bytesAvailable differs from currentTarget.bytesTotal

                  // Note that currentTarget.bytesTotal contains the exact size of the file

              }

       

       

      How to get the raw data without the extra bits/encoding. Does it have to do with serialization ? I've been trying to figure it out but so far without success. So basically what I want is the byteArray returned from URLLoader and the contentType returned by Loader.

       

      Note: I'm not interested in recompressing the image from a bitmap, since this would either degrade its quality or result in an overly big image which would consume too much bandwidth.