gpt4 book ai didi

ios - 捕获并存储用相机拍摄的照片到本地数据库/PhoneGap/Cordova/iOS

转载 作者:技术小花猫 更新时间:2023-10-29 10:06:36 25 4
gpt4 key购买 nike

我目前正在使用 Phonegap/Cordova 和 jQuerymobile 为 iOS 构建一个应用程序。这个想法是用相机拍照并存储捕获的图像以备将来使用。我想将路径/文件名存储到我的本地数据库中,并将图片文件移动到 iPhone 中的持久位置。

有人可以给我举个例子吗?

最佳答案

好的,这是解决方案。

  • 在Html文件中

  • 我有一个图像标签,用于显示相机拍摄的照片:

  • 我有一个运行拍照功能的按钮:拍照

  • 拍照功能是(拍照时,'smallImage'id的scr中填充照片的路径)

    function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
    }

    //Callback function when the picture has been successfully taken
    function onPhotoDataSuccess(imageData) {
    // Get image handle
    var smallImage = document.getElementById('smallImage');

    // Unhide image elements
    smallImage.style.display = 'block';
    smallImage.src = imageData;
    }

    //Callback function when the picture has not been successfully taken
    function onFail(message) {
    alert('Failed to load picture because: ' + message);
    }
  • 现在我想将图片移动到永久文件夹中,然后将链接保存到我的数据库中:

    function movePic(file){ 
    window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError);
    }

    //Callback function when the file system uri has been resolved
    function resolveOnSuccess(entry){
    var d = new Date();
    var n = d.getTime();
    //new file name
    var newFileName = n + ".jpg";
    var myFolderApp = "EasyPacking";

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
    //The folder is created if doesn't exist
    fileSys.root.getDirectory( myFolderApp,
    {create:true, exclusive: false},
    function(directory) {
    entry.moveTo(directory, newFileName, successMove, resOnError);
    },
    resOnError);
    },
    resOnError);
    }

    //Callback function when the file has been moved successfully - inserting the complete path
    function successMove(entry) {
    //I do my insert with "entry.fullPath" as for the path
    }

    function resOnError(error) {
    alert(error.code);
    }
  • 我的文件已保存在数据库中以显示它,我将“file://”放在包含图像 src 的行的前面

希望对您有所帮助。J.

附言:- 非常感谢 Simon Mac Donald (http://hi.im/simonmacdonald) 在 googledocs 上的帖子。

关于ios - 捕获并存储用相机拍摄的照片到本地数据库/PhoneGap/Cordova/iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10335563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com