flash上传头像,截取图像 组件演示

效果图如下:

HTML页面代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>flash上传头像组件演示</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <style type="text/css" media="screen">
        html, body {
            height: 100%;
            background-color: #ffffff;
        }

        #flashContent {
            width: 100%;
            height: 100%;
        }
    </style>

    <script type="text/javascript">
        //function uploadevent(status, picUrl, callbackdata) {
        function uploadevent(status) {
            alert(0);
            //alert(callbackdata); //后端返回数据
            var picUrl = "/upload/";
            status += '';
            switch (status) {
                case '1':
                    var time = new Date().getTime();
                    var filename162 = picUrl + '1.png';
                    var filename48 = picUrl + '2.png';
                    var filename20 = picUrl + "3.png";

                    document.getElementById('avatar_priview').innerHTML = "头像1 : <img src='" + filename162 + "?" + time + "'/> <br/> 头像2: <img src='" + filename48 + "?" + time + "'/><br/> 头像3: <img src='" + filename20 + "?" + time + "'/>";

                    break;
                case '-1':
                    window.location.reload();
                    break;
                default:
                    window.location.reload();
            }
        }
    </script>
</head>
<body>
    <div id="altContent">


        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
            width="650" height="450" id="myMovieName">
            <param name="movie" value="avatar.swf">
            <param name="quality" value="high">
            <param name="bgcolor" value="#FFFFFF">
            <param name="flashvars" value="imgUrl=./default.jpg&uploadUrl=./upfile.aspx&uploadSrc=false" />
            <embed src="avatar.swf" quality="high" bgcolor="#FFFFFF" width="650" height="450" wmode="transparent" flashvars="imgUrl=./default.jpg&uploadUrl=./upfile.aspx&uploadSrc=false"
                name="myMovieName" align="" type="application/x-shockwave-flash" allowscriptaccess="always"
                pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
        </object>

        <!--参数说明
        imgUrl = default.jpg 默认图片
        uploadUrl= upfile.php 接收图片接口
        uploadSrc=false 是否上传原图
        showCame=true 是否显示摄像头
        pCut=162|162 裁切框大小
        pSize=162|162|48|48|20|20 预览保存图片大小

        pData=162|162|48|48|20|20 保存图片大小

        例如: imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false&showCame=true&pCut=162|162&pSize=162|162|48|48|20|20&pData=162|162|48|48|20|20-->

    </div>

    <div id="avatar_priview"></div>

</body>
</html>

 

upfile.aspx 后台处理文件, cookie里保存的值可以取到,session不可以。

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System" %>

<%@ Page Language="C#" %>

<%

String pic = Request.Form["pic"];
String pic1 = Request.Form["pic1"];
String pic2 = Request.Form["pic2"];
String pic3 = Request.Form["pic3"];

string Token = WiSpeed.Common.CookieHelper.GetCookieValue("t");
string t = Session["t"] as string;
//原图
if (pic.Length == 0)
{
}
else
{
byte[] bytes = Convert.FromBase64String(pic); //将2进制编码转换为8位无符号整数数组

string url = "./src.png";
FileStream fs = new FileStream(Server.MapPath(url), System.IO.FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}

byte[] bytes1 = Convert.FromBase64String(pic1); //将2进制编码转换为8位无符号整数数组.
byte[] bytes2 = Convert.FromBase64String(pic2); //将2进制编码转换为8位无符号整数数组.
byte[] bytes3 = Convert.FromBase64String(pic3); //将2进制编码转换为8位无符号整数数组.

 

//图1
string url1 = "./1.png";
FileStream fs1 = new FileStream(Server.MapPath(url1), System.IO.FileMode.Create);
fs1.Write(bytes1, 0, bytes1.Length);
fs1.Close();

//图2
string url2 = "./2.png";
FileStream fs2 = new FileStream(Server.MapPath(url2), System.IO.FileMode.Create);
fs2.Write(bytes2, 0, bytes2.Length);
fs2.Close();

//图3
string url3 = "./3.png";
FileStream fs3 = new FileStream(Server.MapPath(url3), System.IO.FileMode.Create);
fs3.Write(bytes3, 0, bytes3.Length);
fs3.Close();

Response.Write("{\"status\":1}");

%>

  

 

posted @ 2017-02-13 11:17  Vincent_void  阅读(433)  评论(0编辑  收藏  举报