ios - iOS相机的图像旋转功能已加入AS3

标签 ios actionscript-3 camera rotation

我正在通过Flash CS5.5使用AS3开发非本地iOS应用。该应用程序具有同时使用两台相机拍摄照片的功能(显然可以随时拍摄,而不是同时拍摄),而我的问题在于我不知道如何处理我在我的相机上看到的图像的旋转设备。

我正在寻找解决方案,但没有任何解决我的问题的方法。

这是我的代码:

package
{
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.ActivityEvent;
    import flash.events.MouseEvent;
    import flash.media.Camera;
    import flash.media.Video;

    public class Main extends Sprite
    {

        private var cam:Camera;
        private var vid:Video;


        public function Main()
        {
            super();

            // support autoOrients
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            cam = Camera.getCamera();

            if (!cam) 
            {
                trace("No camera is installed.");
            }
            else 
            {
               connectCamera();
            }
        }

        private function connectCamera():void 
        {
            cam.setMode(320, 480, 25); 
            cam.setQuality(0,100);
            vid             = new Video();
            vid.width       = cam.width;
            vid.height      = cam.height; 
            vid.attachCamera(cam);
            addChild(vid);    
        }
    }
}

首先感谢您的宝贵时间。我已经更新了autoOrientation设置,这是我正在管理的代码:
    package 
        {
            import flash.display.DisplayObject;
            import flash.display.Sprite;
            import flash.display.StageAlign;
            import flash.display.StageScaleMode;
            import flash.events.ActivityEvent;
            import flash.events.MouseEvent;
            import flash.media.Camera;
            import flash.media.Video;
            import flash.events.StageOrientationEvent;
            import flash.display.StageOrientation;


            public class Main2 extends Sprite
            {

                private var cam:Camera;
                private var vid:Video;
                public var _currentOrientation:String;




                public function Main2()
                {
                    cam = Camera.getCamera();

                    if (! cam)
                    {
                        trace("No camera is installed.");
                    }
                    else
                    {
                        connectCamera();
                    }
                    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);
                }

                private function connectCamera():void
                {
                    cam.setMode(480, 320, 25);
                    cam.setQuality(0,100);
                    vid= new Video();
                    vid.width = cam.width;
                    vid.height = cam.height;
                    vid.attachCamera(cam);
                    addChild(vid);

                }

                private function orientationChangeListener(e:StageOrientationEvent):void
                {
                    switch (e.afterOrientation)
                    {
                        case StageOrientation.DEFAULT :
                            _currentOrientation = "DEFAULT";
                            //set rotation value here
                            stage.rotation = 0;
                            break;

                        case StageOrientation.ROTATED_RIGHT :
                            _currentOrientation = "ROTATED_RIGHT";
                            //set rotation value here
                            stage.rotation = -90;
                            break;

                        case StageOrientation.ROTATED_LEFT :
                            _currentOrientation = "ROTATED_LEFT";
                            //set rotation value here
                            stage.rotation = 90;
                            break;

                        case StageOrientation.UPSIDE_DOWN :
                            _currentOrientation = "UPSIDE_DOWN";
                            //set rotation value here
                            stage.rotation = 180;
                            break;
                    }
                }


            }
}

尽管句子大小写不同,但是当您启动“app”时,您会看到相机图像旋转了90度,而将设备(iPhone 4)横向放置(左右)时,图像放置得很好。当您向后旋转时,图像会像启动图像一样变差。

先感谢您。

PS:对不起,我的英语。
PS2:已编辑。

最佳答案

您需要侦听设备的方向变化并相应地旋转捕获的图像。

import flash.events.StageOrientationEvent;
import flash.display.StageOrientation;

public var _currentOrientation:String;

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);

private function orientationChangeListener (e:StageOrientationEvent):void {

switch (e.afterOrientation) {
case StageOrientation.DEFAULT :
_currentOrientation = "DEFAULT";
//set rotation value here
break;

case StageOrientation.ROTATED_RIGHT :
_currentOrientation = "ROTATED_RIGHT";
//set rotation value here
break;

case StageOrientation.ROTATED_LEFT :
_currentOrientation = "ROTATED_LEFT";
//set rotation value here
break;

case StageOrientation.UPSIDE_DOWN :
_currentOrientation = "UPSIDE_DOWN";
//set rotation value here
break;
}
}

请注意,仅在发生方向更改后才触发此侦听器,因此我设置了全局变量_currentOrientation,然后在捕获图像时测试其值。

需要注意的另一件事是,还有一个未知的定向状态。

关于ios - iOS相机的图像旋转功能已加入AS3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9784199/

相关文章:

ios - 在 spritekit 中访问子节点

ios - 以编程方式设置 UIViewController 的 View 和生命周期

iphone - 在不移动 subview 的情况下更改旋转中心的问题

apache-flex - 如何从 swf 实例化类?

android - 我的 Flash 应用程序如何才能正确适合所有 Android 设备?

php - actionscript 3.0 是否强大到足以最终成为我唯一的服务器端语言?

安卓保存图片到sd卡报错

ios - UITableView 单元格的动态高度问题(Swift)

javascript - 用javascript控制我的电脑摄像头?

android - 如何像 whatsapp editprofile 一样在 android 中为相机或画廊应用程序制作 Intent 选择器?