闪光-> 字节数组-> AMFPHP-> 图片无效?
我将图像加载到 Flash 中,并使用 JPGEncoder 将图像编码为 ByteArray,并将其发送到 AMF PHP,AMF PHP 将字节数组写入文件。 这一切似乎都工作正常,我可以在 Photoshop CS4 中下载生成的文件,效果非常好。 当我尝试从桌面打开它或在 Flash 中打开它时,它不起作用...Picasa 我的默认图像浏览器显示“无效”
这是我用来将字节数组写入文件的代码 -
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents($filename, $jpg);
就是这样...我使用NetConnection类连接并调用服务,我需要说我正在发送jpg数据吗? 我以为 JPGEncoder 会处理这个问题。 如何在写入文件之前验证字节数组? 我需要设置 MIME 类型还是其他什么吗.. 请原谅这些有点菜鸟的问题,一点知识可能是一件危险的事情。
谢谢
-------------------------------------- 第二部分 -------- ----------------------------------
这里是一些代码 -
1) 将图像加载到 Flash 播放器
item.load();
function _onImageDataLoaded(evt:Event):void {
var tmpFileRef:FileReference=FileReference(evt.target);
image_loader=new Loader ;
image_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onImageLoaded);
image_loader.loadBytes(tmpFileRef.data);
}
function _onImageLoaded(evt:Event):void {
bitmap=Bitmap(evt.target.content);
bitmap.smoothing=true;
if (bitmap.width>MAX_WIDTH||bitmap.height>MAX_HEIGHT) {
resizeBitmap(bitmap);
}
uploadResizedImage(bitmap);
}
function resizeBitmap(target:Bitmap):void {
if (target.height>target.width) {
target.width=MAX_WIDTH;
target.scaleY=target.scaleX;
} else if (target.width >= target.height) {
target.height=MAX_HEIGHT;
target.scaleX=target.scaleY;
}
}
function uploadResizedImage(target:Bitmap):void {
var _bmd:BitmapData=new BitmapData(target.width,target.height);
_bmd.draw(target, new Matrix(target.scaleX, 0, 0, target.scaleY));
var encoded_jpg:JPGEncoder=new JPGEncoder(90);
var jpg_binary:ByteArray=encoded_jpg.encode(_bmd);
_uploadService=new NetConnection();
_uploadService.objectEncoding=ObjectEncoding.AMF3
_uploadService.connect("http://.../amfphp/gateway.php");
_uploadService.call("UploadService.receiveByteArray",new Responder(success, error), jpg_binary, currentImageFilename);
}
非常感谢你帮忙
Im loading images into Flash and using JPGEncoder to encode the image to a ByteArray and send this to AMF PHP which writes out the bytearray to a file. This all appears to work correctly and I can download the resulting file in Photoshop CS4 absolutely fine. When i try to open it from the desktop or open it back in Flash it doesnt work... Picasa my default image browser says "Invalid"
Here is the code i use to write the bytearray to a file -
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents($filename, $jpg);
That's it ... I use the NetConnection class to connect and call the service, do I need to say Im sending jpg data? I assumed that JPGEncoder took care of that. How can I validate the bytearray before writing the file? Do I need to set MIME type or something .. excuse the slightly noob questions, a little knowledge can be a dangerous thing.
Thanks
--------------------------------------- PART II ------------------------------------------
Here is some code -
1) load the image into Flash player
item.load();
function _onImageDataLoaded(evt:Event):void {
var tmpFileRef:FileReference=FileReference(evt.target);
image_loader=new Loader ;
image_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onImageLoaded);
image_loader.loadBytes(tmpFileRef.data);
}
function _onImageLoaded(evt:Event):void {
bitmap=Bitmap(evt.target.content);
bitmap.smoothing=true;
if (bitmap.width>MAX_WIDTH||bitmap.height>MAX_HEIGHT) {
resizeBitmap(bitmap);
}
uploadResizedImage(bitmap);
}
function resizeBitmap(target:Bitmap):void {
if (target.height>target.width) {
target.width=MAX_WIDTH;
target.scaleY=target.scaleX;
} else if (target.width >= target.height) {
target.height=MAX_HEIGHT;
target.scaleX=target.scaleY;
}
}
function uploadResizedImage(target:Bitmap):void {
var _bmd:BitmapData=new BitmapData(target.width,target.height);
_bmd.draw(target, new Matrix(target.scaleX, 0, 0, target.scaleY));
var encoded_jpg:JPGEncoder=new JPGEncoder(90);
var jpg_binary:ByteArray=encoded_jpg.encode(_bmd);
_uploadService=new NetConnection();
_uploadService.objectEncoding=ObjectEncoding.AMF3
_uploadService.connect("http://.../amfphp/gateway.php");
_uploadService.call("UploadService.receiveByteArray",new Responder(success, error), jpg_binary, currentImageFilename);
}
Many thanks for you help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你能检查字节数组的字节序类型吗? 也许它默认为大端
can you check the endian type of the bytearray? maybe it is defaulted to big endian
您的问题出在您的 PHP 服务上。 在 AMFPHP 中,POST 数据是抽象的,因此 AMFPHP UploadService 脚本中需要一个函数,该函数接受 _uploadService.call 中的两个输入参数 --jpg_binary 和 currentImageFilename-- ,如下所示:
Your problem is in your PHP service. In AMFPHP the POST data is abstracted, so what you need in your AMFPHP UploadService script is a function that accepts the two input arguments in your _uploadService.call --jpg_binary and currentImageFilename-- like this:
请注意 contentType 行
PHP
对我来说它工作得很好!
奥利弗
Please mind the contentType line
PHP
For me it works perfectly!
Oliver