8 Replies Latest reply on Jan 4, 2012 4:17 AM by Bhavesh Tank

    Capturing and saving screenshot/video

    Bhavesh Tank

      Hello,

       

      I am new to actionscript and this forum. I have just started using Flash CS5.5 and have just made a very simple app which captures video from the default camera on your computer, and monitors movement.

       

      It works very well but I now want to be able to capture a screenshot of this video and possibly also record a length of this captured video, on demand like the click of a button and want to save this data locally.

       

      I have no idea how to approach this though I have had a look at the camera API but don't really have any ideas I'm hoping someone can point me in the right direction.

        • 2. Re: Capturing and saving screenshot/video
          anilkumar tl Level 1

          var myBitmapData:BitmapData = new BitmapData(imgLoader.width, imgLoader.height);

                      myBitmapData.draw(imgLoader);

                      var jpgEncoder:JPGEncoder = new JPGEncoder(80);

                      var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);

                      var file:FileReference = new FileReference();

                       file.browse(new Array(new FileFilter("Images (*.jpg, *.jpeg)", "*.jpg;*.jpeg")));

                      file.save(imgByteData, "test.jpg");

           

          check it out......

          1 person found this helpful
          • 3. Re: Capturing and saving screenshot/video
            Bhavesh Tank Level 1

            Thanks for the reply Anil.

             

            I am having trouble getting the as3corelib's to work..

             

            I downloaded them, and I have added the lib folder to the class inclusions, like so:

             

            adobeerror.JPG

             

            When I come to typing out the code to import them, I get the prompts where you can press 'enter' and it types the lines out for you, and I can navigate all the way to JPGEncoder, however in compile it says it could not be found.

             

            Here my declarations:

             

            import flash.media.*;

            import flash.events.ActivityEvent;

            import flash.display.Sprite;

            import flash.sampler.NewObjectSample;

            import flash.text.TextField;

            import com.adobe.images.JPGEncoder;

             

            var camera:Camera = Camera.getCamera();

            var t:Timer = new Timer(100);

            var txtField:TextField;

            txtField = new TextField();

            txtField.background = true;

            txtField.selectable = false;

            txtField.autoSize = TextFieldAutoSize.LEFT;

            • 4. Re: Capturing and saving screenshot/video
              Bhavesh Tank Level 1

              Anybody?

               

              Surely this problem has cropped up to someone before.

              • 5. Re: Capturing and saving screenshot/video
                Bhavesh Tank Level 1

                Ok I solved the problem with the ac3corelib's.

                 

                I am now having problems grabbing the BitmapData from imgLoader:

                 

                ArgumentError: Error #2015: Invalid BitmapData.

                          at flash.display::BitmapData/ctor()

                          at flash.display::BitmapData()

                          at LifecamCapture_fla::MainTimeline/fl_MouseClickHandler()

                 

                Here is my code for this layer:

                 

                saveBtn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

                 

                 

                function fl_MouseClickHandler(event:MouseEvent):void

                {

                          // Start your custom code

                          // This example code displays the words "Mouse clicked" in the Output panel.

                          trace("Mouse clicked");

                 

                          var imgLoader:Loader = new Loader();

                                    trace("1");

                          var myBitmapData:BitmapData = new BitmapData(imgLoader.width, imgLoader.height);

                                    trace("2");

                          var jpgEncoder:JPGEncoder = new JPGEncoder(80);

                                    trace("3");

                          var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);

                                    trace("4");

                          var file:FileReference = new FileReference();

                                    trace("5");

                 

                    myBitmapData.draw(imgLoader);

                                    trace("6");

                    file.browse(new Array(new FileFilter("Images (*.jpg, *.jpeg)", "*.jpg;*.jpeg")));

                                    trace("7");

                    file.save(imgByteData, "test.jpg");

                                    trace("8");

                • 6. Re: Capturing and saving screenshot/video
                  Bhavesh Tank Level 1

                  I have managed to get the bitmapData from the video and managed to encode it into a jpeg file, it works, but the resolution of the captured video seems wrong.

                   

                  The canvas for the bitmap is set to 640x480 but the image actually written to it is very small. I guess the problem is when I try to either capture/write the bitmapdata or when I try to encode the bitmapdata to the file, but not exactly sure where.

                   

                  var myBitmapData:BitmapData = new BitmapData(res_x, res_y);

                                      trace("2");

                                      trace(myBitmapData);

                   

                  var jpgEncoder:JPGEncoder = new JPGEncoder(80);

                                      trace("3");

                                      myBitmapData.draw(videoInstance);

                   

                  var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);

                                      trace("4");

                                      trace(imgByteData);

                   

                  var file:FileReference = new FileReference();

                                      trace("5");

                   

                      file.save(imgByteData, "test.jpg");

                                      trace("7");

                   

                  test.jpg

                  • 7. Re: Capturing and saving screenshot/video
                    Bhavesh Tank Level 1

                    250+ views and just one reply?

                     

                    Am I asking about this in the wrong place?

                    • 8. Re: Capturing and saving screenshot/video
                      Bhavesh Tank Level 1

                      I have managed to apply a scaling transformation to a matrix, which I pass to the draw method.

                       

                      A scale of *4 solves this issue.