flex图片另存为

saveas.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<!--http://www.sloppy.cn/blog/article/228.htm-->
    <mx:Script>
        <![CDATA[
            import mx.graphics.codec.JPEGEncoder;
            import mx.graphics.ImageSnapshot;
            private function saveAs():void{
                var en:JPEGEncoder = new JPEGEncoder(100); //压缩图片,100是指质量
                var ba:ByteArray=en.encode(ImageSnapshot.captureBitmapData(img1));//将控件转为BitmapData后再转为ByteArray
                var request:URLRequest = new URLRequest("saveas.php");
                request.method="POST";
                request.data=ba;
                request.contentType = "application/octet-stream";  //这个很重要,设置成流数据
                navigateToURL(request,"_blank");    //因为要浏览器触发下载事件,所以就不用异步方式打开连接了
            }
        ]]>
    </mx:Script>
    <mx:Button x="498" y="276" label="另存到本地" click="saveAs()"/>
    <mx:Image id="img1" x="119" y="124" source="1.png" width="212" height="311" scaleContent="false"/>
</mx:Application>

saveas.php

<?php
$fp = fopen("php.jpg", 'wb');
fwrite($fp,$HTTP_RAW_POST_DATA);
fclose($fp);
echo("<script language=javascript>alert('保存成功!');window.close();</script>");
/*
echo "a";
echo $_POST["data"];
echo $HTTP_RAW_POST_DATA;
*/
?>

    A+
发布日期:2009年05月20日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: