通过使用phonegap和XCode,我为iPad开发了一个iOS应用程序。通过使用PhoneGap1.3.0.js和XCode 4.3,我完成了从ipad相册中获取图像、相机和图像的选择。
主要的问题是我已经更新了X代码版本到X代码5.1.1,并在我的MAC MINI中安装了电话间隔2.9.1版本。但是,当我在ipad2中测试应用程序时,图像捕获和图像选择不起作用。作为新的电话间隙与X代码,我无法确定问题的发生。现在,我正在使用科多瓦.js,这是内置在电话间隔2.9.1。
JavaScript函数正在调用,但是语法
navigator.camera. get Picture();从那条线开始。
我使用的代码如下所示
var imageLength = 0;
function take Picture() {
navigator.camera.get Picture()
};你能帮我修一下吗。
发布于 2014-07-02 04:05:08
试试这个
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(imageURI) {
alert("fire");
// Uncomment to view the base64-encoded image data
console.log(imageURI);
// Get image handle
//
var cameraImage = document.getElementById('image');
// Unhide image elements
//
cameraImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
cameraImage.src = imageURI;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
alert("fire");
// Uncomment to view the image file URI
console.log(imageURI);
// Get image handle
//
var galleryImage = document.getElementById('image');
// Unhide image elements
//
galleryImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
galleryImage.src = 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: 30,
targetWidth: 600,
targetHeight: 600,
destinationType: destinationType.FILE_URI,
saveToPhotoAlbum: true
});
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 30,
targetWidth: 600,
targetHeight: 600,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
// Called if something bad happens.
//
function onFail(message) {
//alert('Failed because: ' + message);
}您可以在这里下载我的示例代码:https://github.com/datomnurdin/com.revivalx.cordova.camera
https://stackoverflow.com/questions/24522653
复制相似问题