Camera image not showing using Cordova/Phonegap API with getPicture and FILE_URI option

时间秒杀一切 提交于 2020-01-03 23:12:56

问题


I'm having this issue with FILE_URI similar to the one raised in another post:

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

I've tried using a simple code similar to the example provided in the Cordova docs.

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,     
        });
    }

I'm using the Cordova 3.1 API from AppGyver on iOS7. I tried using all the combinations of navigator.camera vs Camera, FILE_URI vs NATIVE_URI, and JPG vs PNG. None of these combinations worked. However I still get the right URI path (file:///var/mobile/Applications/…/tmp/cdvphoto024.jpg) but the image won't show when given this path as a source. It works when using DATA_URL on both CAMERA and PHOTOLIBRARY but this is of no use to me since I need to be able to store the path in LocalStorage and move the image file to a permanent location. Any idea how to solve this issue? Or maybe a workaround where I could use the saveToPhotoAlbum option, but then I don't know how to retrieve the path of that newly captured image without going through the getPicture manual selection again. Any idea? Thx

来源:https://stackoverflow.com/questions/24579912/camera-image-not-showing-using-cordova-phonegap-api-with-getpicture-and-file-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!