Flash 闪存加载程序和ByteArray

Flash 闪存加载程序和ByteArray,flash,bytearray,jpeg,base64,loader,Flash,Bytearray,Jpeg,Base64,Loader,我需要能够从磁盘加载jpeg/png图像,并在flex中显示,然后将其作为base64编码字符串发送到服务器。但是一旦加载了图像文件,在我的flash.display.LoaderInfo对象中,bytes属性(类型为ByteArray)包含的字节比文件内容多 例如: 图像文件大小:3089 flash.display.LoaderInfo.ByTest总计:3089 flash.display.LoaderInfo.bytes.长度:3155 由于我需要将flash.display.Loade

我需要能够从磁盘加载jpeg/png图像,并在flex中显示,然后将其作为base64编码字符串发送到服务器。但是一旦加载了图像文件,在我的
flash.display.LoaderInfo
对象中,
bytes
属性(类型为
ByteArray
)包含的字节比文件内容多

例如: 图像文件大小:3089 flash.display.LoaderInfo.ByTest总计:3089 flash.display.LoaderInfo.bytes.长度:3155

由于我需要将
flash.display.LoaderInfo.bytes
编码为base64字符串,我不知道必须将ByteArray对象的哪一部分发送到服务器。 我不想将bytearray内容绘制成位图图像并将其重新编码为jpg,因为我必须保持文件的原始质量

谢谢

一些代码:

private function onDataLoadComplete(event:Event):void {
                var encoder:Base64Encoder = new Base64Encoder();
                //var imagePartBytes:ByteArray = new ByteArray();
                //imagePartBytes.writeBytes(event.target.bytes, 0, event.target.bytesTotal); 
                //imagePartBytes.writeBytes(event.target.bytes, 0, event.target.bytes.length); 
                //imagePartBytes.writeBytes(event.target.bytes, event.target.bytes.length-event.target.bytesTotal, event.target.bytesTotal); 
                encoder.encodeBytes(event.target.bytes);
                var imagePart:String = encoder.flush();
                trace(imagePart);
                data = fileName+";"+event.target.contentType+";"+imagePart;
                _changed = true;
            }

通常,您应该发送bytearray的所有内容。 你是如何加载图像的,你确定你正在接收二进制格式的数据吗? 如果显示加载的图像,是否有任何问题


如果使用base64对数据进行编码,则生成的数据长度将大于原始数据长度,因为您将8位长的数据重新编码为6位。因此,对于一个字节,它可以容纳2个字节。

通常,您应该发送bytearray的所有内容。 你是如何加载图像的,你确定你正在接收二进制格式的数据吗? 如果显示加载的图像,是否有任何问题


如果使用base64对数据进行编码,则生成的数据长度将大于原始数据长度,因为您将8位长的数据重新编码为6位。因此,对于一个字节,它可以容纳两个字节。

帕特里克感谢您的回复。 我找到了解决办法。 我使用文件引用直接将图像加载到flash player,而不是使用加载程序将图像加载到舞台上。我试图对加载程序的ByteArray istead的FileReference.data进行编码,这是一个ByteArray,我需要的:)


这很有效。

帕特里克谢谢你的回复。 我找到了解决办法。 我使用文件引用直接将图像加载到flash player,而不是使用加载程序将图像加载到舞台上。我试图对加载程序的ByteArray istead的FileReference.data进行编码,这是一个ByteArray,我需要的:)

它是有效的

var encoder:Base64Encoder = new Base64Encoder();
encoder.encodeBytes(fileRef.data);
imagePart = encoder.flush();