当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

.net关于高拍仪上传图片后的处理 - 浪潮集体大比武

作者:小梦 来源: 网络 时间: 2024-01-10 阅读:

一.前台页面代码:

<!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();           }      }     %>

网友最爱