好吧,我正在尝试打开照片库,然后从那里开始将其上传到服务器。但目前相机库无法打开。我已经从文档中复制了示例。然后,我在 config.xml 中添加了该设备,同时运行 cordova 插件添加命令。
但是当我运行应用程序并单击按钮时没有任何反应。我是 cordova 插件的新手,而不是 JavaScript 向导。我也在使用 iOS v3.3。
这是在 config.xml 中
<feature name="Camera">
<param name="ios-package" value="CDVCamera" />
</feature>
这是照片.html
<html>
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
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() {
pictureSource=navigator.Camera.PictureSourceType;
destinationType=navigator.Camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
// Show the captured photo
// The in-line CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}
// 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('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
// Show the captured photo
// The in-line CSS rules are used to resize the image
//
largeImage.src = imageURI;
}
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);
}
</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
最佳答案
改变
destinationType: destinationType.FILE_URI
至
destinationType: destinationType.DATA_URL
在 getPhoto() 函数中。
如果这不起作用,请尝试以下操作:
Camera.DestinationType.DATA_URL
另请查看此 URL 以获取更多答案:
Phonegap Camera API Cannot read property data url of undefined
关于javascript - Phonegap打不开相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641375/