首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flash Loader和ByteArray

Flash Loader和ByteArray
EN

Stack Overflow用户
提问于 2009-12-18 17:15:43
回答 2查看 3.6K关注 0票数 1

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

示例:图像文件大小: 3089 flash.display.LoaderInfo.bytesTotal:3089 flash.display.LoaderInfo.bytes.length:3155

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

谢谢

下面是一些代码:

代码语言:javascript
复制
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;
            }
EN

回答 2

Stack Overflow用户

发布于 2009-12-18 17:49:35

帕特里克,谢谢你的回复。我找到了一个解决方案。我使用FileReference将图像直接加载到flash player,然后使用加载器将图像加载到舞台上。我正在尝试对加载器的ByteArray进行编码,而不是我需要的FileReference.data,它是一个ByteArray :)

代码语言:javascript
复制
var encoder:Base64Encoder = new Base64Encoder();
encoder.encodeBytes(fileRef.data);
imagePart = encoder.flush();

而且它是有效的。

票数 1
EN

Stack Overflow用户

发布于 2009-12-18 17:34:12

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1927163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档