2010-07-14 65 views
0

我已經編寫了足夠的代碼來預覽Flash中的網絡攝像機視頻。保存從網絡攝像頭捕獲的靜態圖像在Flash中

現在,我想以10秒的間隔捕捉圖像。

這裏是我的代碼:

import flash.display.BitmapData 
import flash.geom.Matrix 
import com.adobe.images.JPGEncoder; 
import flash.net.FileReference; 

//get the default camera 
//change your Default camera using the Flash Player Settings. 
cam=Camera.get() 
//this event is called whenever permission to access the local camera, is accepted or denied by the user 
cam.onStatus=function(e) 
{ 
    //if we are given permission 
    if(e.code == "Camera.Unmuted") 
    { 
     //start the application 
     initialize() 
    } 
    else 
    { 
     System.showSettings(3) 
    } 
} 

var snapshot:BitmapData=new BitmapData(cam._width,cam._height); 

function takeSnapshot() 
{ 
    snapshot.draw(cam,new Matrix()); 
} 


//if there are no Cameras 
if(cam == null) 
{ 
    System.showSettings(3) 
} 
else 
{ 
    cam.setMode(1024, 768, 30); 
    cam.setQuality(10000,0); 
    output.attachVideo(cam); 
    setInterval(this,"takeSnapshot",1000); 
} 

任何幫助嗎?

我是一個總的Flash新手。

謝謝, Rishi。

+0

您使用的是ActionScript 2還是3? – 2010-07-15 00:53:05

+0

ActionScript 2,我認爲.. – 2010-07-15 08:33:16

+1

這就是actionscript 3的語法:)這可能很好地解釋它:http://www.gotoandlearn.com/play.php?id = 44 ...用JPEG取代PNGEncoder,文件等 – 2010-07-20 10:51:46

回答

1

如果要將其保存到用戶磁盤,請記住,您不能自動執行此操作,因爲出於安全原因,FileReference類的save()方法只能在特定用戶操作後使用(單擊,mousedown,我猜按鍵)。在獲得位圖數據後,您需要使用http://code.google.com/p/as3corelib/的jpeg編碼器對img進行編碼並將其保存到磁盤。事情是這樣的:

var fileBrowser:FileReference = new FileReference(); 

    var bd:BitmapData = new BitmapData(imageContainer.width, imageContainer.height, false, 0xFFFFFF); 

    bd.draw(imageContainer); 

    var encoder:JPGEncoder = new JPGEncoder(35); 

    var bytes:ByteArray = encoder.encode(bd); 

    fileBrowser.save(bytes); 

看一看用於FileReference DOC這裏http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/FileReference.html所以你看,你可以用它做什麼。