//forked from : mogera's 保存サンプル // Web カメラの保存テスト //ダブルクリックで画像を保存する。 package { import com.adobe.images.JPGEncoder; import flash.net.FileReference; import flash.events.*; import flash.net.FileReferenceList; import flash.text.TextField; import flash.text.TextFieldType; import flash.utils.ByteArray; import flash.display.*; import flash.media.*; import flash.geom.Matrix; [SWF(width="464", height="464",backgroundColor="#ffffff",frameRate="30")] public class Save extends MovieClip{ private var mc:MovieClip; private var mt:Matrix = new Matrix(); public function Save() { mc= this; var cam:Camera = Camera.getCamera(); if (cam != null) trace("Camera"+Camera.names); //カメラのキャプチャモードを指定の要件に最も近いネイティブモードに設定 cam.setMode(464,464,30,true); var v:Video = new Video(464, 464); v.attachCamera(cam); mc.addChild(v); //鏡みたいに反転 mt.scale(-1, 1); mt.translate(cam.width,0); mc.transform.matrix=mt; //保存(JPG) mc.stage.doubleClickEnabled = true; mc.stage.addEventListener(MouseEvent.DOUBLE_CLICK,SaveFile(SaveJPG, "test.jpg")); } private function SaveFile(encFunc:Function, fileName:String):Function { return function(e:MouseEvent) : void { var ff:FileReference = new FileReference(); ff.addEventListener(Event.OPEN, function(e:Event):void { trace("open"); } ); ff.addEventListener(ProgressEvent.PROGRESS, function(e:ProgressEvent):void { trace("progress"); } ); ff.addEventListener(Event.COMPLETE, function(e:Event):void { trace("complete"); } ); ff.addEventListener(Event.CANCEL, function(e:Event):void { trace("cancel"); } ); ff.addEventListener(Event.SELECT, function(e:Event):void { trace("select"); } ); ff.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void { trace("ioError"); } ); ff.save(encFunc(), fileName); } } // JPGでセーブ private function SaveJPG() : ByteArray { var bmp_data:BitmapData = new BitmapData(mc.width, mc.height); //鏡みたいに反転 bmp_data.draw(mc, mt); //bmp_data.draw(mc) var jpgEncoder:JPGEncoder = new JPGEncoder(80); var jpgData:ByteArray = jpgEncoder.encode(bmp_data); return jpgData; } } } Webカメラの保存テスト