我正在 Flash Builder 中创建一个 iOS 和 Android 应用程序,该应用程序使用 JPGEncoder 函数将拍摄的图像从设备转换为字节数组,但在 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();
}
}