[聚合文章] .net关于高拍仪上传图片后的处理

c# 2015-11-20 7 阅读

一.前台页面代码:

<!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  >
        <object classid="clsid:454C18E2-8B7D-43C6-8C17-B1825B49D7DE" id="captrue" width="600" height="450">
        </object>
    </div>
    <div >
        <input type="button" value="启动"  onclick="startPlay()"/>
        <input type="button" value="上传"  onclick="upload()"/>
        <input type="button" value="停止"  onclick="stopPlay()"/>
        <input type="checkbox" id="delBlack"  onclick="delBlack(this)"/>
        <label for="delBlack">去黑边</label>
        <input type="checkbox" id="adjust"  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();
           }
           
       }
     %>

注:本文内容来自互联网,旨在为开发者提供分享、交流的平台。如有涉及文章版权等事宜,请你联系站长进行处理。