.net關於高拍儀上傳圖片後的處理

hebeibei發表於2015-11-20

一.前臺頁面程式碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var savePath = "D:\capture\";
        var isStart = false;

        function init() {
            createDir();
        }

        function createDir() {
            captrue.bCreateDir(savePath);
        }

        function startPlay() {
            isStart = captrue.bStartPlay();
        }

        function stopPlay() {
            captrue.bStopPlay();
        }


        function getFileName() {
            var date = new Date();
            var fileName = "" + date.getFullYear();
            var month = date.getMonth() + 1;
            if (month < 10) {
                month = "0" + month;
            }
            fileName += month;
            var day = date.getDate();
            if (day < 10) {
                day = "0" + day;
            }
            fileName += day;
            var hour = date.getHours();
            if (hour < 10) {
                hour = "0" + hour;
            }
            fileName += hour;

            var minute = date.getMinutes();
            if (minute < 10) {
                minute = "0" + minute;
            }
            fileName += minute;

            var second = date.getSeconds();
            if (second < 10) {
                second = "0" + second;
            }
            fileName += second;
            return fileName;
        }

        function delBlack(e) {
            if (e.checked) {
                captrue.vSetDelHBFlag(1);
            } else {
                captrue.vSetDelHBFlag(0);
            }
        }

        function doAdjust(e) {
            if (e.checked) {
                captrue.vSetSkewFlag(1);
            } else {
                captrue.vSetSkewFlag(0);
            }
        }

        function upload() {
            captrue.bSaveJPG("D:\", "JPG2");
            var port;
            if (location.port != "") {
                port = location.port;
            } else {
                port = 80;
            }

            captrue.bUpLoadImage("D:\JPG2.JPG", location.hostname, port, "/upload.aspx");
        }

        window.onload = init;
    </script>
</head>
<body>
    <div style="text-align:center;" >
        <object classid="clsid:454C18E2-8B7D-43C6-8C17-B1825B49D7DE" id="captrue" width="600" height="450">
        </object>
    </div>
    <div style="margin-top: 20px;text-align:center;">
        <input type="button" value="啟動" style="margin-left: 10px;" onclick="startPlay()"/>
        <input type="button" value="上傳" style="margin-left: 10px;" onclick="upload()"/>
        <input type="button" value="停止" style="margin-left: 10px;" onclick="stopPlay()"/>
        <input type="checkbox" id="delBlack" style="margin-left: 10px;" onclick="delBlack(this)"/>
        <label for="delBlack">去黑邊</label>
        <input type="checkbox" id="adjust" style="margin-left: 10px;" onclick="doAdjust(this)"/>
        <label for="adjust">矯正</label>
    </div>
</body>
</html>

二.後臺處方法: (本方法寫在了頁面上)

       HttpFileCollection files = this.Request.Files;
       if (files.Count > 0)
       {
           for (int i = 0; i < files.Count; i++)
           {
               System.IO.Stream stream = files[i].InputStream;
               string fileFullName = files[i].FileName;
               int index = fileFullName.LastIndexOf("\");
               string fileName = fileFullName.Substring(index + 1);
               //得到指定上傳檔案的位元組輸入流   
               int imgDataLen = (int)(stream.Length);
               byte[] imgData = new byte[imgDataLen];
               int n = stream.Read(imgData, 0, imgDataLen);
               stream.Close();
               System.IO.FileStream myFileStream = new System.IO.FileStream(Server.MapPath(fileName), 
                   System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
               myFileStream.Write(imgData, 0, imgDataLen);
               myFileStream.Flush();
               myFileStream.Close();
           }
           
       }
     %>

相關文章