首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在xcode 5.1.1中使用phonegap-1.3.0.js作为摄像机功能

问如何在xcode 5.1.1中使用phonegap-1.3.0.js作为摄像机功能
EN

Stack Overflow用户
提问于 2014-07-02 04:02:08
回答 1查看 319关注 0票数 1

通过使用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();从那条线开始。

我使用的代码如下所示

代码语言:javascript
复制
var imageLength = 0;

function take Picture() {
    navigator.camera.get Picture()
};

你能帮我修一下吗。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-02 04:05:08

试试这个

代码语言: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() {
    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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24522653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档