簡體   English   中英

phonegap相機錯誤類型

[英]phonegap camera error types

我正在使用phonegap / cordova 3.3相機api。 當我調用camera.getPicture方法時,可以設置onError函數。 發生錯誤時,將返回一個數字,例如。 1:用戶中止/取消拍照。

現在的問題是:文檔在哪里? all所有的代碼都意味着什么?

您需要安裝相機cordova插件

https://github.com/apache/cordova-plugin-camera

然后,您可以在此處查看文檔:

https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md

確保在您的項目中實現這些代碼。

javascript

var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
 //
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
 //

function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;
    checkConnection();
}

function onFileSystemSuccess(fileSystem) {
    console.log(fileSystem.name);
    console.log(fileSystem.root.name);
}

function fail(error) {
    console.log(error.code);
}
// Called when a photo is successfully retrieved
 //

function onPhotoDataSuccess(imageURI) {
    // Uncomment to view the base64-encoded image data
    console.log(imageURI);
    // Get image handle
    //
    var smallImage = document.getElementById('image');
    // Unhide image elements
    //
    smallImage.style.display = 'block';
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    smallImage.src = imageURI;
    localStorage.imageUrl = imageURI;
}
// Called when a photo is successfully retrieved
 //

function onPhotoURISuccess(imageURI) {
    // Uncomment to view the image file URI
     console.log(imageURI);
    // Get image handle
    //
    var largeImage = document.getElementById('image');
    // Unhide image elements
    //
    largeImage.style.display = 'block';
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    largeImage.src = imageURI;
    localStorage.imageUrl = imageURI;
}
// A button will call this function
 //

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI,
        saveToPhotoAlbum: true
    });
}
// A button will call this function
 //

function capturePhotoEdit() {
    // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
        quality: 20,
        allowEdit: true,
        destinationType: destinationType.FILE_URI
    });
}
// A button will call this function
 //

function getPhoto(source) {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source
    });
}
// Called if something bad happens.
 //

function onFail(message) {
    alert('Failed because: ' + message);
}

html

<button onclick="capturePhoto();">Capture Photo</button><br />
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo
Library</button> <img id="image" name="image" src="" style=
"display:none;width:100%;" />

嗯,我當時有點困惑,按鈕不是代碼而是消息。 不幸的是,每個平台上的錯誤消息都不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM