actionscript 3 - take a picture of current image from webcam in Flash AS3 -


so i've managed view webcam in as3 app code:

package{     import flash.display.sprite;     import flash.media.camera;     import flash.media.video;      public class webcam extends sprite     {            private var camara:camera;         private var video:video;          public function webcam():void {             setupcamera();         }          private function setupcamera():void         {             video = new video(640, 480);             camara = camera.getcamera();             camara.setmode(640, 480, 30);             video.attachcamera(camara);             addchild(video);         }      }  } 

but i'm wondering if there anyway take picture of current image webcam , save somewhere locally?

edit:

@sean here current code:

var camara; var video;   //get camera reference. camara = camera.getcamera();   //create video instance video = new video(640, 480);   video.attachcamera(camara);  addchild(video);  var bitmapdata:bitmapdata = new bitmapdata(640, 480); bitmapdata.draw(video);  var encoder:jpgencoder = new jpgencoder(); var bytearray:bytearray = encoder.encode(bitmapdata);  navnavclick.addeventlistener(mouseevent.click,function(){ var filereference:filereference = new filereference(); filereference.save(bytearray); }); 

that works well, output image blank (white) image. i've included jpgencoder class too. ideas?

first, need draw image bitmapdata.

var bitmapdata:bitmapdata = new bitmapdata(640, 480); bitmapdata.draw(video); 

then, need encode bitmapdata. recommend encoder uses alchemy, adobe removing flash player. so, should use slower as3corelib jpgencoder.

var encoder:jpgencoder = new jpgencoder(); var bytearray:bytearray = encoder.encode(bitmapdata); 

you have raw bytes of image file, , can write them disk.

var filereference:filereference = new filereference(); filereference.save(bytearray); 

(this part has called user-initiated action, click).


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -