他的龙根本太大了_动漫美女被吸乳视频漫画_欧美xxxx性疯狂bbbb_天天看天天爽天天摸天天添

HTML5網頁掃描二維碼

2018-5-22    seo達人

如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里

[HTML]代碼

<!DOCTYPE html>
<html>
<head>
    <title>二維碼掃描測試</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<style type="text/css">
    html, body {
        height: 100%;
        width: 100%;
        text-align: center;
    }
</style>
<script src="../js/jquery-1.11.1.min.js"></script>
<script>
    //這段代 主要是獲取攝像頭的視頻流并顯示在Video 簽中
    var canvas = null, context = null, video = null;
    window.addEventListener("DOMContentLoaded", function () {
        try {
            canvas = document.getElementById("canvas");
            context = canvas.getContext("2d");
            video = document.getElementById("video");
            var videoObj = { "video": true, audio: false },
                flag = true,
                MediaErr = function (error) {
                    flag = false;
                    if (error.PERMISSION_DENIED) {
                        alert('用戶拒絕了瀏覽器請求媒體的權限', '提示');
                    } else if (error.NOT_SUPPORTED_ERROR) {
                        alert('對不起,您的瀏覽器不支持拍照功能,請使用其他瀏覽器', '提示');
                    } else if (error.MANDATORY_UNSATISFIED_ERROR) {
                        alert('指定的媒體類型未接收到媒體流', '提示');
                    } else {
                        alert('系統未能獲取到攝像頭,請確保攝像頭已正確安裝。或嘗試刷新頁面,重試', '提示');
                    }
                };
            //獲取媒體的兼容代碼,目前只支持(Firefox,Chrome,Opera)
            if (navigator.getUserMedia) {
                //qq瀏覽器不支持
                if (navigator.userAgent.indexOf('MQQBrowser') > -1) {
                    alert('對不起,您的瀏覽器不支持拍照功能,請使用其他瀏覽器', '提示');
                    return false;
                }
                navigator.getUserMedia(videoObj, function (stream) {
                    video.src = stream;
                    video.play();
                }, MediaErr);
            }
            else if (navigator.webkitGetUserMedia) {
                navigator.webkitGetUserMedia(videoObj, function (stream) {
                    video.src = window.webkitURL.createObjectURL(stream);
                    video.play();
                }, MediaErr);
            }
            else if (navigator.mozGetUserMedia) {
                navigator.mozGetUserMedia(videoObj, function (stream) {
                    video.src = window.URL.createObjectURL(stream);
                    video.play();
                }, MediaErr);
            }
            else if (navigator.msGetUserMedia) {
                navigator.msGetUserMedia(videoObj, function (stream) {
                    $(document).scrollTop($(window).height());
                    video.src = window.URL.createObjectURL(stream);
                    video.play();
                }, MediaErr);
            } else {
                alert('對不起,您的瀏覽器不支持拍照功能,請使用其他瀏覽器');
                return false;
            }
            if (flag) {
                //alert('為了獲得更準確的測試結果,請盡量將二維碼置于框中,然后進行拍攝、掃描。 請確保瀏覽器有權限使用攝像功能');
            }
            //這個是拍照按鈕的事件,
            $("#snap").click(function () { startPat(); }).show();
        } catch (e) {
            printHtml("瀏覽器不支持HTML5 CANVAS");
        }
    }, false);
    //打印內容到頁面
    function printHtml(content) {
        $(window.document.body).append(content + "<br/>");
    }
    //開始拍照
    function startPat() {
        setTimeout(function () {//防止調用過快
            if (context) {
                context.drawImage(video, 0, 0, 320, 320);
                CatchCode();
            }
        }, 200);
    }
    //抓屏獲取圖像流,并上傳到服務器
    function CatchCode() {
        if (canvas != null) {
            //以下開始編 數據
            var imgData = canvas.toDataURL("image/jpeg");
            //將圖像轉換為base64數據
            var base64Data = imgData; //在前端截取22位之后的字符串作為圖像數據
            $.ajax({
                type: 'post',
                url: '../ashx/HandlerScan.ashx?method=ParseImage',
                data: 'ImgData=' + base64Data,
                dataType: "json",
                cache: false,
                timeout: 10000,
                success: function (mes) {
                    if (mes.code == '1') {
                        alert('未識別二維碼,請重新掃描!');
                    }
                    else {
                        alert(mes.name);
                    }
                },
                error: function (err) {
                    alert('掃描失敗' + err);
                }
            });
        }
    }
</script>
<body>
    <div id="support"></div>
    <div id="contentHolder">
        <video id="video" width="320" height="320" autoplay></video>
        <canvas id="canvas" style="display:none; background-color:#F00;" width="320" height="320"></canvas><br/>
        <button id="snap" style="display:none; height:50px; width:120px;">開始掃描</button>
    </div>
</body>
</html>  

[C#后臺]

    public class HandlerScan : IHttpHandler
    {
        private JsonResult js = new JsonResult();
        public void ProcessRequest(HttpContext context)
        {
            string result = string.Empty;
            string method = context.Request.QueryString.ToString();//獲取想要做的操作
            switch (method)
            {
                case "method=ParseImage":
                    result = ParseImage(context);
                    break;
                default:
                    break;
            }
            context.Response.ContentType = "text/json";
            context.Response.Write(result);
        }
        private string ParseImage(HttpContext context)
        {
            try
            {
                string imgStr = context.Request.Params["ImgData"].ToString();
                imgStr = imgStr.Replace("data:image/jpeg;base64,", "");
                //整理字符串
                imgStr = imgStr.Replace(" ", "+");
                byte[] arr = Convert.FromBase64String(imgStr);
                MemoryStream ms = new MemoryStream(arr, 0, arr.Length);
                Bitmap bmp = new Bitmap(ms);
                //解析圖片
                Result result = new BarcodeReader().Decode(bmp);
                if(result == null)
                {
                    return "{\"code\":1,\"name\":\"\"}";
                }
                else
                {
                    string[] a = result.Text.Split(','); 
                    string str = "{\"code\":0,\"name\":\"" + a[0] + "\"}";
                    return str; 
                }
            }
            catch (Exception ex)
            {
                return "{\"code\":1,\"msg\":\"" + ex.Message + "\",\"userName\":\"\"}";
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
藍藍設計m.ssll180.com )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務

日歷

鏈接

個人資料

藍藍設計的小編 http://m.ssll180.com

存檔