Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从库中获取图像在phoneGap中不起作用_Javascript_Jquery_Cordova_Camera_Cordova Plugins - Fatal编程技术网

Javascript 从库中获取图像在phoneGap中不起作用

Javascript 从库中获取图像在phoneGap中不起作用,javascript,jquery,cordova,camera,cordova-plugins,Javascript,Jquery,Cordova,Camera,Cordova Plugins,我们需要得到图像表格库。所以我们添加插件到我们的应用程序,然后我们像这样尝试 var pictureSource; // picture source var destinationType; // sets the format of returned value document.addEventListener("deviceready",onDeviceReady,false); function onDeviceReady() { alert("ondev

我们需要得到图像表格库。所以我们添加插件到我们的应用程序,然后我们像这样尝试

var pictureSource;   // picture source
   var destinationType; // sets the format of returned value
 document.addEventListener("deviceready",onDeviceReady,false);
 function onDeviceReady() {
        alert("ondevicereday");
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }
   function onPhotoDataSuccess(imageData) {
    alert("Open");
      var smallImage = document.getElementById('smallImage');
      smallImage.src = "data:image/jpeg;base64," + imageData;
    }
 function capturePhoto(){
    alert("justOpen");
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY });

     }
     function onFail(message) {
        alert('Failed because: ' + message);
      }
但我们无法打开图库。当页面加载“
ondevicereday
”警报显示时,我们单击
openGallery
按钮,它将显示
justOpen
警报,但我们无法打开
因此,请指导我们并告诉我代码中有什么错误

我已经使用cordova的文件API插件导入了它,该文件API插件将允许您访问Android手机中的文件系统

这里是链接


你好,世界
阿帕奇科尔多瓦酒店
连接到设备

设备已准备就绪

干净数据

函数pickImage(){ var lastpotocontainer=document.getElementById(“lastPhoto”); var doc=document.getElementBy window.imagePicker.getPictures( 职能(结果){ 控制台日志(结果); 对于(var i=0;i

这个简单的示例从本地存储器中获取一张图像,并将其显示在应用程序的屏幕上,您可以继续将图像从uri转换为base64,并按自己喜欢的方式使用。现在,这将把已经拍摄的照片填充到html中。希望这有帮助。

重命名
onPhotoDataSuccess
onPhotoURISuccess
@Naveen Dodda您解决了吗?
<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->

        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
                <button style="width:30%;" onclick="pickImage()">Clean Data</button>
                <p id="lastPhoto"></p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
         <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript">
            function pickImage(){
                var lastPhotoContainer = document.getElementById("lastPhoto");
                var doc= document.getElementBy
                window.imagePicker.getPictures(
                function(results) {
                    console.log(results);
                        for (var i = 0; i < results.length; i++) {
                        var imageUri=results[i];
                        console.log('Image URI: ' + results[i]);
                        lastPhotoContainer.innerHTML = "<img src='" + imageUri + "' style='width: 75%;' />";
                        }
                    }, function (error) {
                        console.log('Error: ' + error);
                }
            );
            }
        </script>
    </body>
</html>