关于我的APP,我想拍照并上传到服务器。我参考了这篇文章:从CameraRoll和CameraUI上传图像,但我无法在以下代码块中获取图片内容:
private function readMediaData():void
{
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes( imageBytes );
......
}
imageBytes 将为 0 KB,有人知道为什么吗?谢谢~
关于我的APP,我想拍照并上传到服务器。我参考了这篇文章:从CameraRoll和CameraUI上传图像,但我无法在以下代码块中获取图片内容:
private function readMediaData():void
{
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes( imageBytes );
......
}
imageBytes 将为 0 KB,有人知道为什么吗?谢谢~
我正在解决完全相同的问题。看起来 Air 中有一些错误(或者这是某种“未记录的功能”?)。
问题似乎是,一旦您使用 loadFilePromise() 加载图像,您就会“丢失”数据源,因此 IDataInput 将始终将其长度返回为 0,并且不会将任何内容读入字节数组。这只发生在 iOS 上,它在 Android 上运行良好。您需要做的是编辑您的事件处理程序:
private function onMediaPromiseLoaded(event:Event):void{
event.currentTarget.removeEventListener(Event.COMPLETE, onMediaPromiseLoaded);
bytes = new ByteArray(); //this is an instance variable
dataSource.readBytes(bytes); //read the bytes into it BEFORE doing anything else
//do the rest of the stuff, load picture and add to gallery or whatever
}
它对我有用,我希望这对某人有所帮助。