0 Replies Latest reply on Mar 3, 2011 6:57 AM by geoffdoat

    Webcam Capture AS2 CS5

    geoffdoat

      Hey everyone! I'm attempting to use a webcam to capture images (which this does ok) and then overlay the images over eachother with a low opacity.

       

      The images will be of a users face, each time a new user takes a picture the new face will be overlayed over the old one.

       

      The first problem is, no matter how much I alter the alpha levels, it does not affect the opacity of the bitmap, I know this is probably simple but I'm fairly new to actionscripting!

       

      Also the next step is figuring out how to get the image to stay there once the next one has been taken. I was wondering am I right in thinking of dynamically creating a new movieclip for each bitmap taken and changing the alpha of the movie clip. Would this work as a solution of both problems?

       

      Many thanks for any help!

       

      [CODE]import flash.display.BitmapData;

      import com.adobe.images.JPGEncoder;


      var snd:Sound = new camerasound();


      var bandwidth:int = 0;

      var quality:int = 100;


      var cam:Camera = Camera.getCamera();

      cam.setQuality(bandwidth, quality);

      cam.setMode(320,240,30,false);

      var video:Video = new Video();

      video.attachCamera(cam);

      video.x = 20;

      video.y = 20;

      video.alpha = 10;

      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 = 10;

      }


      save_mc.alpha = 10;



      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;[/CODE]