A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: webcam- bitmap data capture every 5 min

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    2

    webcam- bitmap data capture every 5 min

    Hi Guys,
    I tried posting on AS3 section, but with no luck. It's really very important so please guys help me.
    I have to take a snapshots form my webcam every 5 minutes.
    Now my script is whit a button and its working but my file have to take the picture alone and then again whitout button to send them?

    I saw something on the net but when I try to do it its not working. Please,please its really important and i havent much more time, i read a lot of the stuff here but nothing seams to be to my problem.
    Help is really appreciated.
    Here is my script:
    Actionscript Code:
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    //right click credits menu
    var rightClickMenu:ContextMenu = new ContextMenu();
    var copyright:ContextMenuItem = new ContextMenuItem("Download source code" );
    copyright.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, myLink );
    copyright.separatorBefore = false;
    rightClickMenu.hideBuiltInItems();
    rightClickMenu.customItems.push(copyright);
    this.contextMenu = rightClickMenu;
    function myLink(e:Event){
        navigateToURL(new URLRequest("#"), "_blank" );
    }

    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import com.adobe.images.JPGEncoder;

    var snd:Sound = new camerasound(); //new sound instance for the "capture" button click

    var bandwidth:int = 0; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
    var quality:int = 100; // This value is 0-100 with 1 being the lowest quality.

    var cam:Camera = Camera.getCamera();
    cam.setQuality(bandwidth, quality);
    cam.setMode(320,240,30,false); // setMode(videoWidth, videoHeight, video fps, favor area)
    var video:Video = new Video();
    video.attachCamera(cam);
    video.x = 20;
    video.y = 20;
    addChild(video);

    var bitmapData:BitmapData = new BitmapData(video.width,video.height);

    var bitmap:Bitmap = new Bitmap(bitmapData);
    bitmap.x = 360;
    bitmap.y = 20;
    addChild(bitmap);

    capture_mc.buttonMode = true;
    capture_mc.addEventListener(MouseEvent.CLICK,captureImage);

    function captureImage(e:MouseEvent):void {
        snd.play();
        bitmapData.draw(video);
        save_mc.buttonMode = true;
        save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG);
        save_mc.alpha = 1;
    }

    save_mc.alpha = .5;


    function onSaveJPG(e:Event):void{
        var myEncoder:JPGEncoder = new JPGEncoder(100);
        var byteArray:ByteArray = myEncoder.encode(bitmapData);
       
        var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
       
        var saveJPG:URLRequest = new URLRequest("save.php");
        saveJPG.requestHeaders.push(header);
        saveJPG.method = URLRequestMethod.POST;
        saveJPG.data = byteArray;
       
        var urlLoader:URLLoader = new URLLoader();
        urlLoader.addEventListener(Event.COMPLETE, sendComplete);
        urlLoader.load(saveJPG);
       
        function sendComplete(event:Event):void{
            warn.visible = true;
            addChild(warn);
            warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
            warn.buttonMode = true;
        }

    }

    function warnDown(e:MouseEvent):void{
        navigateToURL(new URLRequest("images/"), "_blank");
        warn.visible = false;
    }

    warn.visible = false;

    And the one I found in some post.
    Actionscript Code:
    video.attachVideo(Camera.get());

    import flash.display.BitmapData
    import flash.geom.*

    var snapshot:BitmapData=new BitmapData(video.width, video.height);
    bitmap_mc = this.createEmptyMovieClip("bitmap_mc",this.getNextHighestDepth());

    function takeSnapshot()
    {
        //draw the current state of the Video object into
        //the bitmap object with no transformations applied
        snapshot.draw(video,new Matrix(), new ColorTransform(), new Object());
        //display the specified bitmap object inside the movie clip
        bitmap_mc.attachBitmap(snapshot,1);

        trace("Bitmap_mc: " + bitmap_mc.width + "x" + bitmap_mc._eight);
        trace("Snapshot: " + snapshot.width + "x" + snapshot.height);
    }

    var interval = setInterval(takeSnapshot, 3000);

  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Hi Guys, I did not thought it will be that hard to switch the code. Can somebody at least tell me how to exchange the buttons for automatic snapshot tacking and the send button for automatic sending the snapshots.

    Thank you very much!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center