科尔多瓦相机没有在div中显示图像

时间:2015-10-05 20:05:20

标签: cordova phonegap-plugins phonegap-build

一切正常,然后div没有显示照片,我不知道我在哪里犯了错误。我正在使用最新版本的phonegap cli-5.2.0,我一直在试图找到我可能出错的地方

html

<div id="myImage"></div>

CSS

#myImage
        {
         width:80%; 
         padding:2%; 
         left:7.5%; 
         top:15%; 
         background-color:#111; 
         height:50%; 
         border: 3px solid #111;
         }

JS

  $(document).ready(function() {
        $("#camera").click(function() {
            navigator.camera.getPicture(onSuccess, onFail, { 
            quality : 75,
            destinationType: Camera.DestinationType.FILE_URI,
            sourceType : Camera.PictureSourceType.CAMERA,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 300,
            targetHeight: 300,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: true });

    function onSuccess(imageURI) {
        var image = document.getElementById('myImage');
        image.src = imageURI;

    }

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

3 个答案:

答案 0 :(得分:1)

你不能把图像放在div上,div没有src,你必须将它放在img标签上

<img id="myImage" src=""/>

答案 1 :(得分:0)

OK then You want to for both then first of all bellow code try for android.

<img id="myImage" >

<script type="text/javascript">
            var profileImage = '';
            function profileCapturePhotoEdit() {
              navigator.camera.getPicture(profileonPhotoDataSuccess, onFail, {
                quality: 20, allowEdit: true,
                correctOrientation: true,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA }
                                         );
            }

            function profileonPhotoDataSuccess(imageData) {
              localStorage.setItem("imageDataProfile","data:image/jpeg;base64," + imageData);
              var imageDataProfile = localStorage.getItem("imageDataProfile");
              document.getElementById('myImage').src = imageDataProfile;
            }

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

          </script>

and add cordova.js and camera related permissions for android.

答案 2 :(得分:0)

我认为&#34; saveToPhotoAlbum选项&#34;必须是假的