0 Replies Latest reply: Jul 13, 2010 1:03 AM by andrejusc RSS

    Problem obtaining BitmapData for a canvas via Javascript

    andrejusc Community Member

      Hi,

       

      For my web application I have one HTML button, which is outside of flash application shown on the same page. Via Flex application I've declared callback function to be called by Javascript in this way:

       

      ExternalInterface.addCallback("cbProcessButton", processButton);

       

      For HTML button I have this:

       

      <input id="bSave" name="button" type="submit" value="Save" onclick="getSWF('${application}').cbProcessButton();" />

       

      And inital lines of processButton function (which is Flex function) are defined as this:

       

                var bitmapData:BitmapData = new BitmapData(canvas.width, canvas.height, false, 0xFFFFFF);
                bitmapData.draw(canvas);
                var jpgEncoder:JPEGEncoder = new JPEGEncoder(85);
                var jpgStream:ByteArray = jpgEncoder.encode(bitmapData);

       

      Now I have problem here. If I call that processButton in this way for my canvas via Javascript - then I get length of jpgStream as 32654 bytes and after save into a file - that jpg file cannot be shown properly.

       

      But if I call the same processButton via a Flex button, which is placed inside my Flex - I get jpgStream in my case of length 33074 bytes and after save to a file - could normally show it later.

       

      I'm using Flex Builder 3 with Flex sdk 3.5.0.12683 installed and later show everything/work via Flash Player v10,1,53,64 installed on WinXP.

       

      Is it known bug/limitation of BitmapData usage in such Javascript scenario? Or is it bad sdk/Flash Player? Are you able to reproduce such in your environment?

       

      I'm really going out of my mind to understand why lengths of encoded data in 2 cases are different. Of course I know about that 2176 Error for other situations dealing with Flex UI, but here I don't get it - so I assume my Javascript scenario is allowed by Adobe so far.

      Any help would be highly appreciated.

       

      Andrejus