3

我遇到的 FILE_URI 问题类似于另一篇文章中提出的问题:

--> Cordova 2.8.1: camera.getPicture with photolibarary source on ios

我尝试使用类似于 Cordova 文档中提供的示例的简单代码。

HTML:

<head>
  <link rel="stylesheet" type="text/css" href="application.css">
  <script src="http://localhost/cordova.js"></script>
  <script src="/components/steroids-js/steroids.js"></script>
  <script src="application.js"></script>
</head>
<body>
    <div>
        <br>
        <button type="button" onclick="takePhoto()">Take photo</button>
        <br>
        <hr>
        <p>Image should appear below:</p>
        <img id="image" width="100%" height="100%" src="">
        <hr>
        <p>Image URI should appear below:</p>
        <p id="URI"></p>
    </div>
</body>
</html>

JS:

    function onCameraSuccess(imageURI) {
        document.getElementById('image').src = imageURI;
        document.getElementById('URI').innerHTML = imageURI;
    }

    function onCameraFail(message) {
        alert('Failed because: ' + message);
    }

    function takePhoto() {
        navigator.camera.getPicture(onCameraSuccess, onCameraFail, { 
            quality: 50,
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: 1,      // 0:Photo Library, 1:Camera, 2:Photo Album
            encodingType: 0,     // 0:JPG 1:PNG
            allowEdit: true,
            correctOrientation: true,
            saveToPhotoAlbum: true,     
        });
    }

我在 iOS7 上使用来自 AppGyver 的 Cordova 3.1 API。我尝试使用 navigator.camera 与 Camera、FILE_URI 与 NATIVE_URI 以及 JPG 与 PNG 的所有组合。这些组合都不起作用。但是,我仍然得到正确的 URI 路径(file:///var/mobile/Applications/…/tmp/cdvphoto024.jpg),但是当将此路径作为源时,图像不会显示。它在 CAMERA 和 PHOTOLIBRARY 上使用 DATA_URL 时有效,但这对我没有用,因为我需要能够将路径存储在 LocalStorage 中并将图像文件移动到永久位置。知道如何解决这个问题吗?或者也许是一种解决方法,我可以使用 saveToPhotoAlbum 选项,但是我不知道如何在不再次通过 getPicture 手动选择的情况下检索新捕获的图像的路径。任何想法?谢谢

4

0 回答 0