1. 程式人生 > >html5 plus 拍照並顯示

html5 plus 拍照並顯示

1.點選拍照按鈕、獲取圖片路徑並顯示到頁面上

mui.plusReady(function() {      document.getElementById("takePic").addEventListener('tap', function() {
        takePhoto();
    });
});
function takePhoto() {
    // 獲取裝置預設的攝像頭物件 
    var cmr = plus.camera.getCamera();
    var res = cmr.supportedImageResolutions[0];//支援畫素
    var
fmt = cmr.supportedImageFormats[0];//支援的圖片格式 //進行拍照 cmr.captureImage(function(path) { //拍照成功回撥函式 //讀取拍照檔案 plus.io.resolveLocalFileSystemURL(path, function(entry) { //顯示 document.getElementById("picShow").src = entry.toLocalURL(); /** * name : 1448346233943.jpg * localURL : file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/doc/1448346233943.jpg * localString : [object Object] */
}, function(e) { //讀取拍照檔案錯誤 outLine("讀取拍照檔案錯誤:" + e.message); }); }, function(err) { //拍照出現error alert(err.message);//錯誤資訊 alert(err.code);//錯誤編碼 }, { resolution: res, format: fmt }); }