当我拍照时,我开始不断收到内存警告。我使用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
}
我确保质量很低,但在崩溃之前它会变慢。
感谢您的帮助!
答案 0 :(得分:3)
最后,我通过修正照片尺寸来解决问题:
/**
* 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);
}
答案 1 :(得分:0)
DATA_URL将图像作为数据流返回。由于返回到程序的字符串值的大小,现代高分辨率相机简单地重载JavaScript引擎。来自我的Apache Cordova API Cookbook:
"使用Camera.DestinationType.DATA_URL存在问题。摄像机图像包含大量数据,将图像转换为字符串并将其传递到Cordova应用程序以超出大多数设备的JavaScript引擎的限制。除非您降低图像的质量或大小,否则当您使用此选项时,您很可能会发现应用程序非常慢或崩溃。"
建议使用FILE_URI,除非拍摄非常小的照片,否则您将永远无法使用DATA_URL。