0

制作一个用于 Android 的 AS3 应用程序,它使用相机胶卷来加载、选择并使用图像。

The cameraroll browser works fine, but when the image is selected, the app crashes - almost every time - as it has worked on a handful of occasions (!?!) We assumed a memory issue and attempted to close all other windows / use smaller相机胶卷等中的照片并尝试不同的设备 - 但无法始终如一地重现成功。也找不到另一个可以工作的 ANE

它在选择照片时失败,并重新启动应用程序...

这是相关代码,任何帮助表示赞赏。

public function openGallery():void {
            var cameraRoll:CameraRoll = new CameraRoll(); 
            if(CameraRoll.supportsBrowseForImage) { 
                cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected); 
                cameraRoll.addEventListener(flash.events.Event.CANCEL, browseCanceled); 
                cameraRoll.addEventListener(flash.events.ErrorEvent.ERROR, mediaError); 
                cameraRoll.browseForImage();
            } 
            else { trace( "Image browsing is not supported on this device."); } 
        }

private function imageSelected(event:MediaEvent):void { 
            trace("Media selected..."); 
            var imagePromise:MediaPromise = event.data as MediaPromise; 
            _dataSource = imagePromise.open(); 
            if(imagePromise.isAsync) { 
                trace("Asynchronous media promise."); 
                var eventSource:IEventDispatcher = _dataSource as IEventDispatcher; 
                eventSource.addEventListener(flash.events.Event.COMPLETE, onMediaLoaded); 
            } else { 
                trace("Synchronous media promise."); 
                readMediaData(); 
            }
        } 

private function onMediaLoaded(event:flash.events.Event):void{
            trace("Media load complete");  

            _mediaBytes = new ByteArray();            
            _dataSource.readBytes(_mediaBytes);                     
            _tempDir = File.createTempDirectory();            
            var now:Date = new Date();            
            var filename:String;            
            filename = now.fullYear + now.month + now.day+now.hours + now.minutes + now.seconds + ".JPG";            
            _file = _tempDir.resolvePath(filename);

            //writing temporal file to display image            
            _stream = new FileStream();            
            _stream.open(_file,FileMode.WRITE);            
            _stream.writeBytes(_mediaBytes);            
            _stream.close();

            if(_file.exists){

                _imageLoader = new Loader();                
                _imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onMediaLoadedBitmapData);                
                _imageLoader.loadBytes(_mediaBytes);

            }

        }   

        private function onMediaLoadedBitmapData(event:Event):void{
            trace("onMediaLoadedBitmapData");
            var loaderInfo:LoaderInfo = LoaderInfo(event.target);            
            _bitmapData = new BitmapData(loaderInfo.width,loaderInfo.height,false,0xFFFFFF);            
            _bitmapData.draw(loaderInfo.loader);
                        addPictureToScreen();
        }
4

1 回答 1

0

我在 iOS 的 Air 中也发生过类似的事情,但它与选取大图像有关。我只是检查了所选图像的尺寸,然后如果它们超过某个点,则使用标量矩阵。听起来您已经考虑过这一点,但也许会进一步研究?

于 2014-07-16T01:48:24.623 回答