[英]How do I capture an Image using Flex 4.5.1, in a mobile project?
我是Flex和ActionScript編程的新手,並且盡可能快地學習它。 我嘗試了一些示例應用程序。 現在,我試圖通過PC附帶的網絡攝像頭使用ActionScript捕獲圖像。
我寫了下面的代碼...
protected var myCam:CameraUI;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if (CameraUI.isSupported){
currentState = "normal";
myCam = new CameraUI();
myCam.addEventListener(MediaEvent.COMPLETE, onComplete);
}
else currentState = "unsupported";
}
protected function btnPic_clickHandler(event:MouseEvent):void
{
img.filters = [];
myCam.launch(MediaType.IMAGE);
}
protected function onComplete(evt:MediaEvent):void
{
img.source = evt.data.file.url;
}
protected function applyFilter():void
{
if (img.filters.length==0)
{
var matrixArray:Array = [.33,.33,.33,0,0,
.33,.33,.33,0,0,
.33,.33,.33,0,0,
0,0,0,1,0];
var blackWhiteFilter:ColorMatrixFilter = new ColorMatrixFilter(matrixArray);
img.filters = [blackWhiteFilter];
btnBW.label = "COLOR";
}
else
{
img.filters = [];
btnBW.label = "B/W FILTER";
}
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="unsupported"/>
</s:states>
<s:layout>
<s:VerticalLayout paddingTop="20" paddingBottom="20" paddingLeft="10" paddingRight="20" gap="40"
horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<s:Label text="This device does not support Camera." width="95%" includeIn="unsupported"/>
<s:HGroup includeIn="normal">
<s:Button id="btnPic" click="btnPic_clickHandler(event)" label="TAKE A PICTURE"/>
<s:Button id="btnBW" click="applyFilter()" label="B/W FILTER" />
</s:HGroup>
<s:Image id="img" height="649" y="124" width="460" x="10" includeIn="normal"/>
但是沒有檢測到相機.. currentsState始終不受支持...有什么問題...
還有其他使用FlexMobileProject捕獲移動設備圖像/視頻的方法嗎?
任何與Flex Mobile Development相關的博客/教程都將為gr8提供幫助。
在文檔中:“使用Camera類從客戶端系統或設備照相機捕獲視頻。使用Video類在本地監視視頻。”
您應該閱讀的第一件事是關於Camera Class的 。
然后簽出Video Class 。
來自文檔的示例:
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.media.Camera;
import flash.media.Video;
public class CameraExample extends Sprite {
private var video:Video;
public function CameraExample() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var camera:Camera = Camera.getCamera();
if (camera != null) {
camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
video = new Video(camera.width * 2, camera.height * 2);
video.attachCamera(camera);
addChild(video);
} else {
trace("You need a camera.");
}
}
private function activityHandler(event:ActivityEvent):void {
trace("activityHandler: " + event);
}
}
}
看看您是否可以使之工作,然后詢問有關過濾圖片並保存圖片的另一個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.