Web調用安卓,蘋果手機網路攝影機,本地圖片和檔案

來源:互聯網
上載者:User

標籤:review   strong   function   onchange   ipa   需要   obj   頭像   multi   

在之前一家公司的時候要做一個app裡面有上傳頭像的功能,當時研究了好久,找到了一篇文章關於h5網路攝影機以及相簿的調用的,所以就解決了這個問題了!!我這裡記錄一下以便後面有人需要,可以參考一下!!!!

下面是完整的一個HTML頁面內容,放在伺服器上然後瀏覽就可以了,只支援Chrome和Safari核的瀏覽器,QQ瀏覽器,Chrome,Safari瀏覽器都可以。在不同的手機和瀏覽器上面展現的方式不一樣。

<!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>

Web調用安卓,蘋果手機網路攝影機,本地圖片和檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.