access your web cam and take a snapshot using flash actionscript 3.0
In this post i will help you how to access your web cam and take a snap shot and save it as in JPEG format.
6. Goto the webcam fla and give the class name =vido.
7.Run the flash file and take the snapshot and save it as jpeg.
- Create a new flash file with name WebCam.
- Create a button with instance name "_capt " in the stage
- Then create a new actionscript 3 file with name "vido". copy and paste the following code into that and save it..
package
{
import com.adobe.images.JPGEncoder;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.media.Video;
import flash.media.Camera;
import flash.display.Sprite;
import flash.events.*;
import flash.display.MovieClip;
import flash.net.FileReference;
import flash.utils.ByteArray;
import flash.geom.Matrix;
[SWF(width=640,height=480,frameRate=24)]
public class vido extends Sprite
{
public var _camera:Camera;
public var _video:Video;
public var _capt:MovieClip;
public var _snap:Bitmap;
public var _snapContent:BitmapData;
public var _fileRefer:FileReference;
public var bytes:ByteArray;
public function vido()
{
_camera=Camera.getCamera();
_video=new Video(320,240);
_video.attachCamera(_camera);
addChild(_video);
_capt.addEventListener(MouseEvent.CLICK,takeCapt);
}
public function takeCapt(evt:MouseEvent)
{
var _snapContent:BitmapData=new BitmapData(320,240, false, 0);
BitmapData(_snapContent.draw(_video));
var _snap:Bitmap=new Bitmap();
_snap.bitmapData=_snapContent;
addChild(_snap);
_snap.x = 304;
var jpgEncode:JPGEncoder = new JPGEncoder();
var bytes:ByteArray = jpgEncode.encode(_snapContent);
var _fileRefer=new FileReference();
_fileRefer.save(bytes, "image.jpeg");
}
}
}
6. Goto the webcam fla and give the class name =vido.
7.Run the flash file and take the snapshot and save it as jpeg.