Flex使用不带cameraUI的相机

时间:2012-01-19 00:45:13

标签: flash actionscript-3 flex camera flash-builder4.5

关于我正在制作的应用程序的另一个问题。因此,当用户注册时,他需要拍照。我想在不使用cameraUI的情况下这样做。我遵循了一些教程,但应用程序没有运行。我没有错误,但相机没有显示。这是我做的:

    <?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        activate="view1_activateHandler(event)"
        title="Camera Test">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>


    <fx:Script>
        <![CDATA[
            import mx.core.UIComponent;

            import spark.components.Image;
            import spark.components.VideoDisplay;
            import spark.components.ViewNavigator;

            private var cam:Camera;
            private var video:Video;
            private var uic:UIComponent;

            protected function cameraButton_clickHandler(event:MouseEvent):void
            {
                if(!cam){
                    trace("whut");
                    cameragroup.removeAllElements();
                    this.cam=Camera.getCamera();
                    cam.setQuality(0,100);

                    cam.setMode(cameragroup.width, cameragroup.height, 30, false);
                    if(cam){
                        trace("camera added");
                        this.video=new Video(cameragroup.width, cameragroup.height);

                        video.attachCamera(cam);

                        this.uic=new UIComponent();
                        uic.addChild(video);

                        var m:Matrix=new Matrix();
                        m.rotate(Math.PI/2);
                        video.transform.matrix=m;

                        var m2:Matrix = new Matrix();
                        m2.translate((video.width+cameragroup.width/4)-this.frame.x, 5);
                        uic.transform.matrix=m2;

                        cameragroup.addElement(uic);
                        cameraButton.label="shoot";
                    }
                }
            }

            protected function view1_activateHandler(event:Event):void
            {
                this.cameraButton.label="shoot";
            }

        ]]>
    </fx:Script>

    <s:VGroup width="100%" height="100%" horizontalAlign="center" paddingBottom="30" paddingLeft="10" paddingRight="10" paddingTop="30">
        <s:Group id="frame" width="100%" height="100%">
            <s:Rect width="100%" height="100%">
                <s:fill>
                    <s:SolidColor color="0x000000" alpha="0.2"/>
                </s:fill>
            </s:Rect>
            <s:Group id="cameragroup" width="210" height="220"/>
        </s:Group>

        <s:Spacer height="100%"/>
        <s:HGroup width="100%" horizontalAlign="center">
            <s:Button id="cameraButton" width="50%" height="80" label="start" click="cameraButton_clickHandler(event)"/>
        </s:HGroup>
    </s:VGroup>
</s:View>

这是完整的.mxml文件。我逐行忽略了代码,但没有发现任何错误。

Grtz

1 个答案:

答案 0 :(得分:0)

在您的Application-app.xml

确保有以下内容。

<uses-permission android:name="string" />

在我们的案例中:

<uses-permission android:name="android.permission.CAMERA"/>

这里有更详细的解释: http://developer.android.com/guide/topics/manifest/uses-permission-element.html