1. <nobr id="easjo"><address id="easjo"></address></nobr>

      <track id="easjo"><source id="easjo"></source></track>
      1. 
        

      2. <bdo id="easjo"><optgroup id="easjo"></optgroup></bdo>
      3. <track id="easjo"><source id="easjo"><em id="easjo"></em></source></track><option id="easjo"><span id="easjo"><em id="easjo"></em></span></option>
          貴州做網站公司
          貴州做網站公司~專業!靠譜!
          10年網站模板開發經驗,熟悉國內外開源網站程序,包括DEDECMS,WordPress,ZBlog,Discuz! 等網站程序,可為您提供網站建設,網站克隆,仿站,網頁設計,網站制作,網站推廣優化等服務。我們專注高端營銷型網站,企業官網,集團官網,自適應網站,手機網站,網絡營銷,網站優化,網站服務器環境搭建以及托管運維等。為客戶提供一站式網站解決方案?。?!

          VUE用瀏覽器調用USB攝像頭

          來源:互聯網轉載 時間:2024-01-29 08:30:49

          公司需求:

            在線上瀏覽器調用攝像頭拍照上傳

            本人實現調用攝像頭拍照以下代碼 經測試 (Google Chrome 88.0.4324.182) 版本可用 各位可以試一試其他瀏覽器

            參考代碼 https://www.jb51.net/article/193305.htm

          以下代碼直接用就可以

          <template>    <p >        <video  :width="videoWidth" :height="videoHeight" autoplay></video>        <canvas style="display:none;"  :width="videoWidth" :height="videoHeight"></canvas>        <p v-if="imgSrc" >            <img :src="imgSrc" alt="" >        </p>        <p>            <button @click="getCompetence()">打開攝像頭</button>            <button @click="stopNavigator()">關閉攝像頭</button>            <button @click="setImage()">拍照</button>        </p>    </p></template><script>    export default {        data() {            return {                videoWidth: 540,                videoHeight: 410,                imgSrc: '',                thisCancas: null,                thisContext: null,                thisVideo: null,                validTip: '驗證中'            }        },        computed: {},        methods: {            /*             *@author wf_Huang             *@Time 2019/6/5 0005 17:35             *@function  調用權限             *****************************************/            getCompetence() {                var _this = this                this.thisCancas = document.getElementById('canvasCamera')                this.thisContext = this.thisCancas.getContext('2d')                this.thisVideo = document.getElementById('videoCamera')                // 舊版本瀏覽器可能根本不支持mediaDevices,我們首先設置一個空對象                if (navigator.mediaDevices === undefined) {                    navigator.mediaDevices = {}                }                // 一些瀏覽器實現了部分mediaDevices,我們不能只分配一個對象                // 使用getUserMedia,因為它會覆蓋現有的屬性。                // 這里,如果缺少getUserMedia屬性,就添加它。                if (navigator.mediaDevices.getUserMedia === undefined) {                    navigator.mediaDevices.getUserMedia = function (constraints) {                        // 首先獲取現存的getUserMedia(如果存在)                        var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia                        // 有些瀏覽器不支持,會返回錯誤信息                        // 保持接口一致                        if (!getUserMedia) {                            return Promise.reject(new Error('getUserMedia is not implemented in this browser'))                        }                        // 否則,使用Promise將調用包裝到舊的navigator.getUserMedia                        return new Promise(function (resolve, reject) {                            getUserMedia.call(navigator, constraints, resolve, reject)                        })                    }                }                var constraints = {                    audio: false,                    video: {width: this.videoWidth, height: this.videoHeight, transform: 'scaleX(-1)'}                }                navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {                    // 舊的瀏覽器可能沒有srcObject                    if ('srcObject' in _this.thisVideo) {                        _this.thisVideo.srcObject = stream                    } else {                        // 避免在新的瀏覽器中使用它,因為它正在被棄用。                        _this.thisVideo.src = window.URL.createObjectURL(stream)                    }                    _this.thisVideo.onloadedmetadata = function () {                        _this.thisVideo.play()                    }                }).catch(err => {                    console.log(err)                })            },            /*             *@author wf_Huang             *@Time 2019/6/5 0005 17:32             *@function  繪制圖片             *****************************************/            setImage() {                var _this = this                // 點擊,canvas畫圖                _this.thisContext.drawImage(_this.thisVideo, 0, 0, _this.videoWidth, _this.videoHeight)                // 獲取圖片base64鏈接                var image = this.thisCancas.toDataURL('image/png')                _this.imgSrc = image                this.$emit('refreshDataList', this.imgSrc)            },            /*             *@author wf_Huang             *@Time 2019/6/5 0005 17:44             *@function  base64轉文件             *****************************************/            dataURLtoFile(dataurl, filename) {                var arr = dataurl.split(',')                var mime = arr[0].match(/:(.*?);/)[1]                var bstr = atob(arr[1])                var n = bstr.length                var u8arr = new Uint8Array(n)                while (n--) {                    u8arr[n] = bstr.charCodeAt(n)                }                return new File([u8arr], filename, {type: mime})            },            /*             *@author wf_Huang             *@Time 2019/6/10 0010 3:41             *@function  關閉攝像頭             *****************************************/            stopNavigator() {                this.thisVideo.srcObject.getTracks()[0].stop()            }        },        mounted() {            this.getCompetence()        },        beforeDestroy() {            this.stopNavigator()        }    }</script><style lang="scss" scoped>    .camera_outer {        position: relative;        overflow: hidden;        background-size: 100%;        video, canvas, .tx_img {            -moz-transform: scaleX(-1);            -webkit-transform: scaleX(-1);            -o-transform: scaleX(-1);            transform: scaleX(-1);        }        .btn_camera {            position: absolute;            bottom: 4px;            left: 0;            right: 0;            height: 50px;            background-color: rgba(0, 0, 0, 0.3);            line-height: 50px;            text-align: center;            color: #ffffff;        }        .bg_r_img {            position: absolute;            bottom: 0;            left: 0;            right: 0;            top: 0;        }        .img_bg_camera {            position: absolute;            bottom: 0;            left: 0;            right: 0;            top: 0;            img {                width: 100%;                height: 100%;            }            .img_btn_camera {                position: absolute;                bottom: 0;                left: 0;                right: 0;                height: 50px;                line-height: 50px;                text-align: center;                background-color: rgba(0, 0, 0, 0.3);                color: #ffffff;                .loding_img {                    width: 50px;                    height: 50px;                }            }        }    }</style>
          上一篇:fabric基本使用
          下一篇:-etc-alternatives

          網絡推廣與網站優化公司(網絡優化與推廣專家)作為數字營銷領域的核心服務提供方,其價值在于通過技術手段與策略規劃幫助企業提升線上曝光度、用戶轉化率及品牌影響力。這...

          在當今數字化時代,公司網站已成為企業展示形象、傳遞信息和開展業務的重要平臺。然而,對于許多公司來說,網站建設的價格是一個關鍵考量因素。本文將圍繞“公司網站建設價...

          在當今的數字化時代,企業網站已成為企業展示形象、吸引客戶和開展業務的重要平臺。然而,對于許多中小企業來說,高昂的網站建設費用可能會成為其發展的瓶頸。幸運的是,隨...

          Cf綠色聯盟怎么退?聽說退了會封號?你好,LZ。CF綠色聯盟can 不要放棄。我建議既不退出也不開G,如果LZ堅持退出,可以開G,封了就自動退出。只會封半年,就看LZ有沒有耐心了。我再提醒你一次,如果你打開它,它被封了,你覺得你能找到什么樣的解封者?這樣肯定不行。這些都是騙人的。;的錢。cf綠色聯盟怎么退出?成功加入綠色聯盟,過一段時間想退出怎么辦?打開CF官網綠色聯盟的網頁,點擊退出綠色聯盟。...

          vivo手機電池容量怎么找?這個可以到VIVO官網自助查詢,具體方法::一、簡單的方法建議使用百度找不到VIVO手機官網,然后然后點擊。二、進入到VIVO手機官網以后,找到要網站查詢的手機型號,這里以X23手機為例,進入頁面。三、直接進入以后中,選擇“參數規格”選項。四、進入到以后就這個可以查詢到手機電池的容量了。vivo手機在哪里可以查電池多少毫安?vivo手機又不能在手機上查找到手機的電池容量...

          巴巴多斯國家簡介 請詳細介紹巴巴多斯這個國家?巴巴多斯島在哪里? 巴巴多斯(Barbados)珊瑚石灰巖島位于東加勒比海小安的列斯群島最東端。它被海洋包圍,西面與圣盧西亞、圣文森特、格林納丁斯和格林納達隔水相望。1966年11月30日,巴巴多斯擁有一個穩定的民主政權,獨立于此。他是英聯邦的成員,他的名字來自葡萄牙語,指的是野生無花果樹。巴巴多斯國內生產總值為48.21億美元,人均國內生產總值為...

          TOP
          国产初高中生视频在线观看|亚洲一区中文|久久亚洲欧美国产精品|黄色网站入口免费进人
          1. <nobr id="easjo"><address id="easjo"></address></nobr>

              <track id="easjo"><source id="easjo"></source></track>
              1. 
                

              2. <bdo id="easjo"><optgroup id="easjo"></optgroup></bdo>
              3. <track id="easjo"><source id="easjo"><em id="easjo"></em></source></track><option id="easjo"><span id="easjo"><em id="easjo"></em></span></option>