我是 Phonegap 的新人。我想使用 Phonegap 拍摄照片。我尝试了文档中的以下代码,但相机未启动。请告诉我我做错了什么?我的代码是
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="js/phonegap.js"></script>
<script src="js/jquery.js"></script>
<script type="text/javascript">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("OnDeviceReady...");
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
function onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
}
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality : 50,
destinationType : destinationType.DATA_URL
});
}
function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality : 20,
allowEdit : true,
destinationType : destinationType.DATA_URL
});
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality : 50,
destinationType : destinationType.FILE_URI,
sourceType : source
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
window.onload = onDeviceReady;
</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>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From
Photo Album</button>
<br>
<img style="display: none; width: 60px; height: 60px;" id="smallImage"
src="" />
<img style="display: none;" id="largeImage" src="" />
</body>
</html>
请告诉我哪里出错了。
这是我的相机插件
<plugins>
<plugin
name="Storage"
value="org.apache.cordova.Storage" />
<plugin
name="Camera"
value="com.foregroundcameraplugin.ForegroundCameraLauncher" />
</plugins>
提前谢谢您。
最佳答案
尝试使用 Phonegap 自己的相机插件而不是自定义插件。
您可以在此处查看文档:Phonegap Camera API
另外,在引用phonegap.js时,您不必放置js/phonegap.js。你可以像这样引用 src =“phonegap.js”
如果您使用 Phonegap Build,这是插入插件的正确方法:
<gap:plugin name="org.apache.cordova.camera"/>
关于javascript - 使用 Phonegap 拍摄照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25503139/