3 Replies Latest reply: Jul 31, 2012 12:20 PM by the0bot RSS

    Image to ByteArray synchronously

    Francisc Community Member

      Hello,

       

      How can I turn a string image path to a ByteArray synchronously?

       

      Thank you.

        • 1. Re: Image to ByteArray synchronously
          highlightscript Community Member

          // import flash.display.BitmapData;

          // import com.adobe.images.JPGEncoder;

          // import flash.display.BitmapData;

          private static final function encodeToJPEG(data:BitmapData, quality:Number = 75):ByteArray

          {

              var encoder:JPGEncoder = new JPGEncoder(quality);

              return encoder.encode(data);

          }

           

          now load image to Image component as below :-

           

          var myImage:Image = new Image();

          myImage.source = "imagesource.jpg";

          // bitmapdata of uicomponent

          var myBitmapData:BitmapData = getUIComponentBitmapData(myImage);

          // jpeg byte array of uicomponent

          var jpgByteArray:ByteArray = encodeToJPEG(myBitmapData);

          • 2. Re: Image to ByteArray synchronously
            Francisc Community Member

            Hm, so you're saying this will work without need for listeners and loaders and all that jazz?

            var myBitmapData:BitmapData = getUIComponentBitmapData(myImage);

            • 3. Re: Image to ByteArray synchronously
              the0bot

              var myBitmapData:BitmapData = getUIComponentBitmapData(myImage);

               

              Where is that function coming from?

               

              I get a "call to undefined method" error......