【问题标题】:Recieve a Memory warning iOS after using camera with Cordova将相机与 Cordova 一起使用后,iOS 收到内存警告
【发布时间】:2014-11-07 19:36:04
【问题描述】:

当我拍照时,我开始不断收到内存警告。我正在使用带有这些设置的 Cordova 3.5 和相机插件。

var _config;      
var pictureSource;
var destinationType; // sets the format of returned value.
var encodingType; // enconding type 0=JPG 1=PNG

/**
 * Initialize camera plugin.
 * @param {object} config - settings.
 */
function initialize(config) {
    alert("CAMERA is comming!!");
    // Wait for Cordova to connect with the device
    document.addEventListener('deviceready', onDeviceReady, false);
}

/** 
 * Cordova is ready to be used!
 * @param {object} config - settings.
 */
function onDeviceReady() {

    console.log("CAMERA is READY!!");
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
    encodingType = navigator.camera.EncodingType;
    capturePhoto();
}

/**
 * Set camera plugin settings.
 * @param {object} config - settings.
 */
function setConfig(config) {
    _config = config;
}

/**
 * Take picture using device camera and retrieve image as base64-encoded string.
 */
function capturePhoto() {
    setConfig({ quality: 20, destinationType: destinationType.DATA_URL, encodingType: 0});
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, _config);
}

/**
 * Photo is successfully retrieved.
 * @callback getPicture~onPhotoDataSuccess
 * @param {string} imageData - A base64-encoded image.
 */
function onPhotoDataSuccess(imageData) {
    //Edit photo
}   

我确保质量很低,但它会变慢直到崩溃。

感谢大家的帮助!

【问题讨论】:

  • 你在什么设备上测试这个?

标签: ios cordova camera


【解决方案1】:

最后,我通过修复照片尺寸解决了这个问题:

 /**
 * Take a picture and get the image as base64-encoded string.
 */
function capturePhoto() {
    setConfig({ quality: 20, targetWidth: 600, targetHeight: 600, correctOrientation: true, destinationType: destinationType.DATA_URL, encodingType: 0});
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, _config);
}

【讨论】:

    【解决方案2】:

    DATA_URL 将图像作为数据流返回。由于返回给程序的字符串值的大小,现代高分辨率相机只会使 JavaScript 引擎过载。来自我的 Apache Cordova API Cookbook:

    “使用 Camera.DestinationType.DATA_URL 存在问题。相机图像包含大量数据,将图像转换为字符串并将其传递给 Cordova 应用程序以使用它超出了大多数设备的 JavaScript 引擎的限制. 除非您降低图像的质量或大小,否则您很可能会在使用此选项时发现应用程序非常缓慢或崩溃。”

    建议改用 FILE_URI,除非您拍摄非常小的照片,否则您将永远无法使用 DATA_URL。

    【讨论】:

    • 感谢您的回答!我知道,这就是我将质量设置为 20 的原因。我必须使用 DATA_URL,因为拍照后有一个照片编辑步骤,我无法加载本地文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2011-07-01
    • 2011-04-30
    相关资源
    最近更新 更多