Ios 将摄像头与Cordova一起使用后,收到内存警告
当我拍照时,我开始连续收到记忆警告。我正在使用Cordova 3.5和带有这些设置的摄像头插件Ios 将摄像头与Cordova一起使用后,收到内存警告,ios,cordova,camera,Ios,Cordova,Camera,当我拍照时,我开始连续收到记忆警告。我正在使用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} conf
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
}
我确保质量很低,但速度会变慢,直到崩溃
谢谢你的帮助 DATA\u URL将图像作为数据流返回。由于返回到程序的字符串值的大小,现代的高分辨率相机只会使JavaScript引擎过载。从我的Apache Cordova API食谱中: “使用Camera.DestinationType.DATA\u URL时出现问题。摄像头图像包含大量数据,将图像转换为字符串并将其传递给Cordova应用程序进行处理超出了大多数设备JavaScript引擎的限制。除非您降低图像的质量或大小,否则在使用此选项时,您很可能会发现应用程序非常慢或崩溃。”
建议改为使用文件URI,除非拍摄非常小的照片,否则永远无法使用数据URL。最后,我通过调整照片大小解决了问题:
/**
* 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);
}
你在什么设备上测试这个?谢谢你的回答!我知道,这就是为什么我将质量设置为20。我必须使用DATA_URL,因为拍照后有照片编辑步骤,我无法加载本地文件。