Capturing photos using a webcam using ActionScript

I have a simple actionscript file with a webcam and image. What I want to do is when the button is pressed, I want to capture this moment of the webcam and image and display it in the DIV in the browser. How to capture him? I guess bitmaps should be used. I want to do this with code

+5
source share
2 answers

Here is what I wrote myself to answer this question. Tested in Chrome, FF and IE9.

You need a Base64 encoder (here here ) and a png / jpg encoder (for example, from the Flex library).

AS code:

package
{
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.external.ExternalInterface;
    import flash.media.Camera;
    import flash.media.Video;

    [SWF(width="640", height="480", backgroundColor="#000000")]
    public class CameraToJS extends Sprite
    {
        private var camera:Camera;
        private var video:Video;

        public function CameraToJS()
        {
            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
            stage.addEventListener(MouseEvent.CLICK, saveSnapshot);
        }

        protected function addedToStageHandler(event:Event):void
        {
            camera = Camera.getCamera(); 
            video =  new Video();
            video.attachCamera(camera);
            addChild(video);
        }

        protected function saveSnapshot(event:MouseEvent):void
        {
            var bmData:BitmapData = new BitmapData(video.width, video.height);
            bmData.draw(video);

            var encoder:PNGEncoder = new PNGEncoder();

            ExternalInterface.call("image", Base64.encodeByteArray(encoder.encode(bmData)));
        }
    }
}

Javascript Code:

function image(data)
{
    document.getElementById("img").src = "data:image/png;base64,"+ data;
}
+6
source

This link can help you, doing exactly what you want.

http://www.xarg.org/project/jquery-webcam-plugin/

0
source

All Articles