Photo Booth - Flash 攝像頭捕捉圖像

fmms 12年前發布 | 21K 次閱讀 PHP AS3 多媒體處理

Photo Booth是一個基于AS3 + PHP5開發,能夠從攝像頭獲取圖像的開源項目。

Photo Booth - Flash 攝像頭獲取圖像


ActionScript 3.0 代碼:
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;</pre>PHP代碼:

</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1325770046640

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!