如何在移动项目中使用 Flex 4.5.1 捕获图像?

发布于 2024-12-18 12:12:50 字数 2382 浏览 1 评论 0原文

我是 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 移动开发相关的博客/教程都会有 gr8 帮助..谢谢...

I am a newbie in Flex and ActionScript programming and learning it as fast as I can. I have tried few sample applications. Now I am trying to capture the image using ActionScript through the webcam attached with the PC.

I have written following code...

        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"/>    

But the camera is not getting detected.. currentsState is always unsupported... Is there anything wrong...

Any other way to capture image/video for mobile devices using FlexMobileProject..?

Any blog/tutorial related to Flex Mobile Development will be of gr8 help..Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2024-12-25 12:12:50

来自文档:
“使用 Camera 类从客户端系统或设备摄像头捕获视频。使用 Video 类在本地监视视频。”

您应该阅读的第一件事是关于 Camera 类

然后查看视频类

文档中的示例:

    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);
    }
}
}

看看您是否可以使该位工作,然后询问有关过滤图片并保存它的另一个问题。

From the docs:
"Use the Camera class to capture video from the client system or device camera. Use the Video class to monitor the video locally."

The first thing you should read is about the Camera Class.

Then check out the Video Class.

Example from the docs:

    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);
    }
}
}

See if you can get that bit working, and then ask another question about filtering the pic and saving it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文