0

我在 Dreameweaver CS6 中使用最新版本的 phonegap 软件。我从 github 网站上获取了起始示例 HTML 文件并将其导入 DW。然后我测试了那个应用程序,所有这些都与我的位置、地图等一起工作。

但是,我现在更改了代码,以便能够在我的 Android 手机上拍照或选择图片,并且每次我这样做/或关闭应用程序时。

HTML 代码是:

<!DOCTYPE html>
<html>
  <head>
    <title>Capture Photo</title>
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value 

    document.addEventListener("deviceready",onDeviceReady,false);

    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    function onPhotoDataSuccess(imageData) {
      var smallImage = document.getElementById('smallImage');
      smallImage.style.display = 'block';
      smallImage.src = imageData;
    }

    function onPhotoURISuccess(imageURI) {
      var largeImage = document.getElementById('largeImage');

      largeImage.style.display = 'block';
      largeImage.src = imageURI;
    }

    function capturePhoto() {
      navigator.camera.getPicture(getPhoto, onFail, { quality: 50, destinationType: destinationType.FILE_URI });
    }

    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100, allowEdit: false }); 
    }

    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100, 
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

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

    </script>
  </head>
  <body>
    <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />
  </body>
</html>

config.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns       = "http://www.w3.org/ns/widgets"
    xmlns:gap       = "http://phonegap.com/ns/1.0"
    id              = "com.xxxxxxxx.DKGApp"
    version         = "1.0.0">

    <name>DKG App</name>

    <description>
        An app that allows uploading their random images they take to our facebook website!
    </description>

    <author href    ="http://www.xxxxxxxx.com"  email       ="mail@xxxxxxxx.com">
        David
    </author>

    <gap:splash src="splash.png" />

    <icon src="icon.png" gap:role="default" />

    <feature name="http://api.phonegap.com/1.0/network" />
    <feature name="http://api.phonegap.com/1.0/camera"/>
    <feature name="http://api.phonegap.com/1.0/file"/>
    <feature name="http://api.phonegap.com/1.0/media"/>

    <preference name="android-minSdkVersion" value="7" />
    <preference name="orientation" value="portrait" />
    <preference name="target-device" value="universal" />
</widget>

我是否遗漏了一些必要的东西才能让它工作而不是每次都崩溃?

谢谢!

4

2 回答 2

0

I also faced the same issue. i fixed the issue using foreground-camera-plugin.

just go to this link and follow the steps.

https://code.google.com/p/foreground-camera-plugin/

于 2013-05-20T13:50:33.087 回答
0

您收到内存不足错误。请不要使用 DATA_URL。返回一个 3000x2000 像素的 base64 编码图像会占用应用程序中的所有可用内存。请改用 FILE_URI。

于 2012-07-11T20:11:33.847 回答