## 相机插件 ##
### 5.1拍照 ###
```
插件说明:调用相机拍照,成功后返回图片路径
插件名称:navigator.camera
调用方法:getPicture
入参类型:JSON
```
>入参:详见:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/#module_camera.CameraOptions
>调用实例:
```
// 设置参数
function setOptions(srcType) {
var options = {
// Some common settings are 20, 50, and 100
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
// In this app, dynamically set the picture source, Camera or photo gallery
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true //Corrects Android orientation quirks
}
return options;
}
// 调用相机
function openCamera(selection) {
var srcType = Camera.PictureSourceType.CAMERA;
var options = setOptions(srcType);
var func = createNewFileEntry;
navigator.camera.getPicture(function cameraSuccess(imageUri) {
displayImage(imageUri);
// You may choose to copy the picture, save it somewhere, or upload.
func(imageUri);
}, function cameraError(error) {
console.debug("Unable to obtain picture: " + error, "app");
}, options);
}
// 显示图片
function displayImage(imgUri) {
var elem = document.getElementById('imageFile');
elem.src = imgUri;
}
```
>返回结果:
```
返回图片的路径
```
---
### 5.2清理临时文件 ###
```
插件说明:删除调用getPicture后保存在临时存储中的图片文件
插件名称:navigator.camera
调用方法:cleanup
入参类型:无
```
>入参:无参数
>调用实例:
```
navigator.camera.cleanup(onSuccess, onFail);
function onSuccess() {
console.log("Camera cleanup success.")
}
function onFail(message) {
alert('Failed because: ' + message);
}
```
>返回结果:
```
无返回结果
```
---