navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] );
navigator.camera.getPicture(onSuccess, onFail, { quality: 50 }); function onSuccess(imageData) { var image = document.getElementById('myImage'); image.src = "data:image/jpeg;base64," + imageData; } function onFail(message) { alert('Failed because: ' + message); }
navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); function onSuccess(imageURI) { var image = document.getElementById('myImage'); image.src = imageURI; } function onFail(message) { alert('Failed because: ' + message); }
Capture Photo
function(imageData) { // 对图像进行处理 }
// 显示图片 function cameraCallback(imageData) { var image = document.getElementById('myImage'); image.src = "data:image/jpeg;base64," + imageData; }
function(message) { // 显示有用信息 }
{ quality : 75, destinationType : Camera.DestinationType.DATA_URL, sourceType : Camera.PictureSourceType.CAMERA, allowEdit : true, encodingType : Camera.EncodingType.JPEG, targetWidth : 100, targetHeight : 100};
Camera.DestinationType = { DATA_URL : 0, //返回Base64编码字符串的图像数据 FILE_URI : 1 //返回图像文件的URI }
Camera.PictureSourceType = { PHOTOLIBRARY : 0, CAMERA : 1, SAVEDPHOTOALBUM : 2 }
Camera.EncodingType = { JPEG : 0, // 返回JPEG格式图片 PNG : 1 // 返回PNG格式图片 };
Camera.MediaType = { PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType //默认值,返回的是Picture,返回由DestinationType指定的格式 VIDEO: 1, // allow selection of video only, WILL ALWAYS RETURN FILE_URI //选出的只能是video类型,返回值是FILE_URI ALLMEDIA : 2 //allow selection from all media types 允许选出的是所有类型