0

所以,我正在开发一个在 Adob​​e Air 和 Actionscript 3.0 中使用相机的应用程序,我知道 CameraUI 等,但我只是在定义使用相机拍摄的图像时遇到问题,所以我可以 bitmapData 和所有爵士乐,这是我的代码

import flash.media.CameraUI;



var cameraUI:CameraUI = new CameraUI();

if (CameraUI.isSupported ) 
{
    cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected); 
    cameraUI.addEventListener(MediaEvent.ERROR, imageError);
    cameraUI.addEventListener(MediaEvent.CANCEL, imagecancelled);
    cameraUI.launch(MediaType.IMAGE); 
}

那么,无论如何定义使用相机拍摄的图像。谢谢

4

1 回答 1

1

从文档:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraUI.html#includeExamplesSummary

编辑

[我的移动应用程序的相机代码]

package com.shaunhusain.fingerPainting.tools 
{
    import flash.display.Loader;
    import flash.display.Stage;
    import flash.events.ErrorEvent;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MediaEvent;
    import flash.events.TouchEvent;
    import flash.media.CameraUI;
    import flash.media.MediaPromise;
    import flash.media.MediaType;

    public class CameraTool extends ToolBase implements ITool
    {
        //--------------------------------------------------------------------------------
        //              Variables
        //--------------------------------------------------------------------------------
        private var deviceCameraApp:CameraUI = new CameraUI();
        private var imageLoader:Loader; 

        //--------------------------------------------------------------------------------
        //              Constructor
        //--------------------------------------------------------------------------------
        public function CameraTool(stage:Stage) {
            super(stage);

            if( CameraUI.isSupported )
            {
                trace( "Initializing camera..." );

                deviceCameraApp.addEventListener( MediaEvent.COMPLETE, imageCaptured );
                deviceCameraApp.addEventListener( Event.CANCEL, captureCanceled );
                deviceCameraApp.addEventListener( ErrorEvent.ERROR, cameraError );
            }
            else
            {
                trace( "Camera interface is not supported.");
            }
        }

        //--------------------------------------------------------------------------------
        //              Handlers
        //--------------------------------------------------------------------------------
        public function takeAction(event:TouchEvent=null):void
        {
            model.disableNextAutosave = true;
            deviceCameraApp.launch( MediaType.IMAGE );
        }

        //--------------------------------------------------------------------------------
        //              Camera UI functions
        //--------------------------------------------------------------------------------

        private function imageCaptured( event:MediaEvent ):void
        {
            trace( "Media captured..." );

            var imagePromise:MediaPromise = event.data;

            if( imagePromise.isAsync )
            {
                trace( "Asynchronous media promise." );
                imageLoader = new Loader();
                imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
                imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );

                imageLoader.loadFilePromise( imagePromise );
            }
            else
            {
                trace( "Synchronous media promise." );
                imageLoader.loadFilePromise( imagePromise );
                showMedia( imageLoader );
            }
        }

        private function captureCanceled( event:Event ):void
        {
            trace( "Media capture canceled." );
        }

        private function asyncImageLoaded( event:Event ):void
        {
            trace( "Media loaded in memory." );
            showMedia( imageLoader );    
        }

        private function showMedia( loader:Loader ):void
        {
            loader.scaleX=-1;
            layerM.addLayer( loader );
        }

        private function cameraError( error:ErrorEvent ):void
        {
            trace( "Error:" + error.text );
        }

        public function toString():String
        {
            return "Loading CameraUI";
        }

    }
}

这是我项目中的一个示例: https ://github.com/wafflejock/FingerPainting/blob/master/FlashBuilderProject/FingerPainting/src/com/shaunhusain/fingerPainting/tools/CameraTool.as

演示/无耻自我宣传:

https://play.google.com/store/apps/details?id=air.com.chitowngames.DigitalDoodler

您可以更改有关加载程序的 showMedia 函数中发生的情况。因此,如果您想访问 BitmapData,只需执行以下操作:

(loader.content as Bitmap).bitmapData
于 2013-06-06T18:54:30.160 回答