闪存加载程序和ByteArray [英] Flash Loader and ByteArray
问题描述
我需要能够从磁盘加载JPEG / PNG图像,并显示在弯曲并将其发送到一台服务器为Base64 EN codeD字符串。但是,一旦图像文件被加载,在我的 flash.display.LoaderInfo在
对象时,<code>字节属性(类型为的ByteArray
)包含不是文件内容的字节。
例如:
图像文件大小:3089
flash.display.LoaderInfo.bytesTotal:3089
flash.display.LoaderInfo.bytes.length:3155
因为我需要带code中的 flash.display.LoaderInfo.bytes
用base64字符串,我不知道从ByteArray客体的哪一部分,我必须发送到服务器。
我并不想画的ByteArray内容为位图图像,并重新连接code将其为jpg,因为我必须保持原始文件的质量。
感谢
一些code:
私有函数onDataLoadComplete(事件:事件):无效{
变种EN codeR:Base64En codeR =新Base64En codeR();
// VAR imagePartBytes:ByteArray将=新的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);
EN coder.en codeBytes(event.target.bytes);
VAR imagePart:字符串= EN coder.flush();
跟踪(imagePart);
数据=文件名+,+ event.target.contentType +,+ imagePart;
_changed = TRUE;
}
帕特里克感谢您的答复。
我找到了解决办法。
我使用的是一个FileReference直接加载图像到Flash Player和比使用加载器加载的形象的舞台。我试图连接code中的FileReference.data这是一个字节数组,一个我需要的装载机的的ByteArray istead:)
变种EN codeR:Base64En codeR =新Base64En codeR();
EN coder.en codeBytes(fileRef.data);
imagePart = EN coder.flush();
和它的作品。
I need to be able to load a jpeg/png image from disk and show it in flex and send it to a server as a base64 encoded string. But once the image file is loaded, in my flash.display.LoaderInfo
object, the bytes
property (type of ByteArray
) contains more byte than the file content.
Example: image file size: 3089 flash.display.LoaderInfo.bytesTotal:3089 flash.display.LoaderInfo.bytes.length:3155
As i need to encode the flash.display.LoaderInfo.bytes
in base64 string, i don't know which part of the ByteArray objet i must send to server.
I don't want to draw the bytearray content into a Bitmap image and re-encode it as jpg because i must keep the original quality of the file.
Thanks
some code:
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;
}
Patrick thank you for your response. I found a solution. I was using a FileReference to load an image directly to flash player and than using a Loader to load the image to the stage. I was trying to encode the Loader's ByteArray istead of the FileReference.data which is a ByteArray, the one i need :)
var encoder:Base64Encoder = new Base64Encoder();
encoder.encodeBytes(fileRef.data);
imagePart = encoder.flush();
and it works.
这篇关于闪存加载程序和ByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!