• 手机端调用摄像头拍照


       1.最简单方法是input取图像:这里需要引导用户进图库后直接拍照 mark-zhq[4]

    <input type="file" id="browseFile" onchange="" accept="images/*">
    <input type="button" id="saveimg" value="保存图片" />

        2.调用navigator.getUserMedia方法:手机端--苹果、安卓浏览器、微信浏览器都不支持,本人测的UC浏览器支持。navigator.getUserMedia浏览器支持情况见:http://caniuse.mojijs.com/Home/Html/item/key/stream/index.html

    1. <!doctype html>
      <html>
      <head>
      <meta charset="utf-8" />
      <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
      </head>
      <body>
      <video id="video" width="640" height="480" autoplay></video>
      <button id="snap">Snap Photo</button>
      <canvas id="canvas" width="640" height="480"></canvas>
      <script type="text/javascript">
      window.addEventListener("DOMContentLoaded", function() {
          var canvas = document.getElementById("canvas"),
              context = canvas.getContext("2d"),
              video = document.getElementById("video"),
              videoObj = { "video": true },
              errBack = function(error) {
                  console.log("Video capture error: ", error.code); 
              };
      
          // 多浏览器兼容调用摄像头
          if(navigator.getUserMedia) { // Standard
              navigator.getUserMedia(videoObj, function(stream) {
                  video.src = stream;
                  video.play();
              }, errBack);
          } else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
              navigator.webkitGetUserMedia(videoObj, function(stream){
                  video.src = window.webkitURL.createObjectURL(stream);
                  video.play();
              }, errBack);
          }
          else if(navigator.mozGetUserMedia) { // Firefox-prefixed
              navigator.mozGetUserMedia(videoObj, function(stream){
                  video.src = window.URL.createObjectURL(stream);
                  video.play();
              }, errBack);
          }
      }, false);
        //截取图像
      document.getElementById("snap").addEventListener("click", function() {
          context.drawImage(video, 0, 0, 640, 480);
      });
      </script>
      </body>
      </html>

      3.微信开发的可以调用微信JS SDK接口

    2. wx.chooseImage({
          count: 1, // 默认9
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
          success: function (res) {
              var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
          }
      });

       4.还有一种是通过jQuery.webcam去做,需要用户安装flash插件,请自行百度---

  • 相关阅读:
    POJ1985 树的直径(BFS
    POJ2186 强连通分量+缩点
    AIM Tech Round 5C. Rectangles 思维
    POJ2553 汇点个数(强连通分量
    hdu6370 并查集+dfs
    UVALive 7037:The Problem Needs 3D Arrays(最大密度子图)
    POJ 3155:Hard Life(最大密度子图)
    HDU 5527:Too Rich(DFS+贪心)***
    HDU 5534:Partial Tree(完全背包)***
    Wannafly挑战赛1:Treepath(DFS统计)
  • 原文地址:https://www.cnblogs.com/web-easy/p/5288275.html
Copyright © 2020-2023  润新知