zoukankan      html  css  js  c++  java
  • 移动端H5调用摄像头(选择上传图片)

    <label>照相机</label>
    <input type="file" id='image' accept="image/*" capture='camera'>
    <br>
    <label>摄像机</label>
    <input type="file" id='video' accept="video/*" capture='camcorder'>

    多选:
    <input type="file" id="file" multiple>

    在各个机型都可以点击 file 调用相册 和 摄像头拍照 
    1. 在老版本的安卓中,必须加上capture,否则只能调用相册 
    2. 在IOS中 加了capture,就只能调用摄像头不能调用相册

    判断ios,如果是ios就去掉capture属性.
    let info=navigator.userAgent.toLowerCases();
    if(info.match(/iPhonesOS/i)){

      dom.removeAttribute("capture")  

      }

    读取图片(fileChoose即为input)

    fileChoose.change=()=>{

      let file=fileChoose.files[0],

      reader=new FileReader();

      reader.onLoad=()=>{

        img.src=reader.result

      };

      reader.readAsDataURL(file)

    }

  • 相关阅读:
    面向对象之单例模式
    面向对象之元类
    面向对象高级1
    面向对象进阶2
    面向对象进阶1
    面向对象基础
    MySQL事务
    【应用容器引擎】Docker笔记
    【Spring Boot】三、嵌入式的Servlet容器
    MySQL优化分析
  • 原文地址:https://www.cnblogs.com/brainworld/p/8868822.html
Copyright © 2011-2022 走看看