JPEG编码器冻结应用程序

时间:2013-01-19 02:39:10

标签: android ios flash-builder bytearray bitmapdata

我在Flash Builder中创建一个iOS和Android应用程序,它使用JPGEncoder函数将拍摄的图像从设备转换为bytearray但在iOS中我的应用程序冻结,在Android中,屏幕变黑并持续一分钟左右然后继续以下是我正在使用的代码。

private var uploadData:ByteArray;
        protected var camera:CameraUI;
        protected var loader:Loader;
        public var file:File;

        protected function takePhoto():void {
            if (CameraUI.isSupported){
                camera = new CameraUI();
                camera.addEventListener(MediaEvent.COMPLETE, savePhoto);
                camera.launch(MediaType.IMAGE);
            }
        }

        protected function savePhoto(e:MediaEvent):void 
        {
            uploadProgress.visible = true;
            var imagePromise:MediaPromise = e.data;
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPhotoBitmapLoadComplete);
            loader.loadFilePromise(imagePromise);
        }

        protected function onPhotoBitmapLoadComplete(e:Event):void
        {
            var loaderInfo:LoaderInfo = e.target as LoaderInfo;
            if (CameraRoll.supportsAddBitmapData)
            {
                var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height);
                bitmapData.draw(loaderInfo.loader);
                file = File.applicationStorageDirectory.resolvePath("receipt" + new Date().time + ".jpg");
                var stream:FileStream = new FileStream()
                stream.open(file, FileMode.WRITE);
                var j:JPEGEncoder = new JPEGEncoder();
                var bytes:ByteArray = j.encode(bitmapData);
                stream.writeBytes(bytes, 0, bytes.bytesAvailable);
                stream.close();

                uploadData = bytes;
                SetupWebService();
            }
        }

1 个答案:

答案 0 :(得分:1)

因为编码器不是异步的,编码大图像可能需要一段时间;特别是jpegs,特别是在移动设备上。

有异步编码器,但不允许自我升级。提示,提示。

编辑:规则被定罪!以下是关于异步编码的博客文章(和代码)的链接:http://blog.leeburrows.com/2011/01/saving-an-image-to-hd-with-actionscript-part-2/