zoukankan      html  css  js  c++  java
  • 【转】H5调用照相机等设备

    使用input标签 type值为file,可以调用系统默认的照相机、相册、摄像机、录音功能:

    <input type="file" accept="image/*" capture="camera">
    
    <input type="file" accept="video/*" capture="camcorder">
    
    <input type="file" accept="audio/*" capture="microphone">
    

      

    属性说明
    accept 打开的系统文件目录
    capture 系统所捕获的默认设备,camera:照相机;camcorder:摄像机;microphone:录音;
    multiple 多选,multiple优先级高于capture,<input type="file" accept="image/*" multiple>

    测试发现存在很多兼容性问题,下面将测试出的部分结果列出:

    设备安卓IOS
    camera 相机、图库、文件管理器等混合选择项 相机
    camcorder 摄像机 摄像机
    microphone 录音 相机
     

     安卓调用相机.jpg

    <!DOCTYPE HTML>
    <html>
    <head>
        <title>上传图片</title>
        <meta charset="utf-8">
    </head>
    <body>
        <iframe name="uploadfrm" id="uploadfrm" style="display: none;"></iframe>
        <form name="formHead" method="post" action="" id="formHead" enctype="multipart/form-data" target="uploadfrm">
    
            <div>
                <div>
                    <input type="file" name="file_head" id="file_head" onchange="javascript:setImagePreview();" />
                </div>
                <div>
                    <div id="DivUp" style="display: none">
                        <input type="submit" data-inline="true" id="BtnUp" value="确认上传" data-mini="true" />
                    </div>
                </div>
            </div>
        </form>
        <div data-role="fieldcontain">
            <div id="localImag">
                <img id="preview" width="-1" height="-1" style="display: none" />
            </div>
        </div>
            
    
        <script type="text/javascript">
            function setImagePreview() {
                var preview, img_txt, localImag, file_head = document.getElementById("file_head"),
                picture = file_head.value;
                if (!picture.match(/.jpg|.gif|.png|.bmp/i)) return alert("您上传的图片格式不正确,请重新选择!"),
                !1;
                if (preview = document.getElementById("preview"), file_head.files && file_head.files[0]) preview.style.display = "block",
                    preview.style.width = "63px",
                    preview.style.height = "63px",
                    preview.src = window.navigator.userAgent.indexOf("Chrome") >= 1 || window.navigator.userAgent.indexOf("Safari") >= 1 ? window.webkitURL.createObjectURL(file_head.files[0]) : window.URL.createObjectURL(file_head.files[0]);
                else {
                    file_head.select(),
                    file_head.blur(),
                    img_txt = document.selection.createRange().text,
                    localImag = document.getElementById("localImag"),
                    localImag.style.width = "63px",
                    localImag.style.height = "63px";
                    try {
                        localImag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)",
                        localImag.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img_txt
                    } catch(f) {
                        return alert("您上传的图片格式不正确,请重新选择!"),
                        !1
                    }
                    preview.style.display = "none",
                    document.selection.empty()
                }
                return document.getElementById("DivUp").style.display = "block",
                !0
            }
        </script>
    </body>
    </html>
    

      

  • 相关阅读:
    IGS_学习笔记09_IREP生成服务后台工具Soagenerate.sh
    PLSQL_PLSQL调优健康检查脚本SQLHC(案例)
    IGS_学习笔记08_IREP通过soapUI测试客户化Web Service调用(案例)
    IGS_学习笔记07_IREP通过页面测试客户化Web Service调用(案例)
    PLSQL_Oracle簇表和簇表管理Index clustered tables(案例)
    IGS_学习笔记06_IREP发布客户化集成接口为Web Service(案例)
    PLSQL_Oracle外部表的概念和使用(案例)
    DBA_Oracle Erp加密和解密账户密码(案例)
    IGS_学习笔记05_IREP开发Concurrent Program为客户化集合接口(案例)
    PLSQL_Oracle物化视图Material View的基本概念和用法 (概念)
  • 原文地址:https://www.cnblogs.com/guxingzhe/p/15039902.html
Copyright © 2011-2022 走看看