mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import * as util from 'ionic/util';
|
|
|
|
export class Camera {
|
|
static getPicture(options) {
|
|
return new Promise((resolve, reject) => {
|
|
if (!navigator.camera) {
|
|
console.warn('Camera: no camera plugin installed. Pictures will not work.')
|
|
resolve(null);
|
|
return;
|
|
}
|
|
|
|
var options = util.defaults({
|
|
quality: 80,
|
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
|
sourceType: window.Camera.PictureSourceType.CAMERA,
|
|
allowEdit: true,
|
|
encodingType: window.Camera.EncodingType.JPEG,
|
|
popoverOptions: window.CameraPopoverOptions,
|
|
saveToPhotoAlbum: false
|
|
}, options);
|
|
|
|
navigator.camera.getPicture(function (imageData) {
|
|
resolve(imageData);
|
|
}, function (err) {
|
|
reject(err);
|
|
}, options);
|
|
});
|
|
}
|
|
static cleanup() {
|
|
return new Promise((resolve, reject) => {
|
|
navigator.camera.cleanup(function () {
|
|
resolve();
|
|
}, function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}
|