3 Replies Latest reply on Sep 6, 2010 10:22 PM by flex2008

    Problem while trying to take screenshoot with ImageSnapshot.captureImage() method.

    flex2008 Level 3

      While clicking the take screenshot button,i expect to get the screenshot of the complete screen.But instead i am getting only a portion of it.I debugged the application,but could not find out a reason for the same.What i understood is that inside the captureImage method in ImageSnapShot the height and width are being modified.But i am not able to see where exactly it is happening since debugger says source cannot be found.Can anyone please help me with this?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" borderColor="red" borderStyle="solid" width="100%" height="100%"
                      layout="vertical"
                      verticalAlign="middle"
                      backgroundColor="#EEEEEE">
          
          <mx:Script>
              <![CDATA[
                  import mx.core.IUIComponent;
                  import mx.graphics.ImageSnapshot;
                  import mx.managers.PopUpManager;
                  
                  protected function button1_clickHandler(event:MouseEvent):void
                  {
                      var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(this);
                      var imageByteArray:ByteArray = imageSnap.data as ByteArray;
                      loader.load(imageByteArray);
                  }
      
              ]]>
          </mx:Script>
          <mx:SWFLoader id="loader"/>
          <mx:ApplicationControlBar dock="true">
              <mx:Button label="Take screenshot" click="button1_clickHandler(event)"/>
          </mx:ApplicationControlBar>
      </mx:Application>
      
        • 1. Re: Problem while trying to take screenshoot with ImageSnapshot.captureImage() method.
          ShardulSingh Level 3

          Hi,

          There are many reasons why it is not working:-

          1) you are never using the height with the loader

          2)you are capturing the entire application and again adding that image shot inside same application so wht will happen?Let suppose you application

          size is 1200 * 800 then how can u add inside the same which is also containing the orginal too.

           

          Pls try this its working fine for any other object:-

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
               borderColor="red" borderStyle="solid" width="100%" height="100%"
                          layout="vertical"
                          verticalAlign="middle"
                          backgroundColor="#EEEEEE">
             
              <mx:Script>
                  <![CDATA[
                      import mx.core.IUIComponent;
                      import mx.graphics.ImageSnapshot;
                      import mx.managers.PopUpManager;
                     
                      protected function button1_clickHandler(event:MouseEvent):void
                      {
                          var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(canvas1);
                          var imageByteArray:ByteArray = imageSnap.data as ByteArray;
                          loader.load(imageByteArray);
                      }

                  ]]>
              </mx:Script>
          <mx:ApplicationControlBar dock="true">
              <mx:Button label="Take screenshot" click="button1_clickHandler(event)"/>
          </mx:ApplicationControlBar>

           

          <mx:VBox width="100%" height="100%">
               <mx:Canvas id="canvas1" width="500" height="300" backgroundColor="0xFF0000" />
               <mx:SWFLoader id="loader" width="500" height="300"/>
          </mx:VBox>   
            
              </mx:Application>

           

           

           

           

           

          with Regards,

           

          Shardul Singh Bartwal

          • 2. Re: Problem while trying to take screenshoot with ImageSnapshot.captureImage() method.
            flex2008 Level 3

            I dont think it is the problem of the loader height or the way in which the loader is used.This is just a sample application i used to illustrate the problem.In the actual scenario i am showing the screenshot in a popup.If you debug the application and take a look at captureImage method in ImageSnapShot,you can see that the width and height of the ImageSnapshot being created is small.I am not sure where exactly and why this is happening.If there is another button next to the take screenshot button in the control bar,the height and width will be reduced such that it will just show the two buttons properly,but ideally i want the whole app screenshot.