The Camera API allows a user to pick a photo from their photo album or take a picture.
Camera.getPhoto({
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE
}).then(
function(fileUri) {
console.log(fileUri);
// fileUri will contain a path that can passed to the Filesystem API
// to read the raw data of the image, copy the picture or save it somewhere
// if desired (or pass destinationType: Camera.DestinationType.DATA_URL to getPicture)
},
(error) => {
// Handle error
console.log(error);
}
);
window.Camera.getPhoto({quality: 50,
destinationType: window.Camera.DestinationType.FILE_URI,
sourceType: window.Camera.PictureSourceType.CAMERA,
encodingType: window.Camera.EncodingType.JPEG,
mediaType: window.Camera.MediaType.PICTURE,
}).then(
function (fileUri) {
console.log(fileUri);
// fileUri will contain a path that can passed to the Filesystem API
// to read the raw data of the image, copy the picture or save it somewhere
// if desired (or pass destinationType: Camera.DestinationType.DATA_URL to getPicture)
},
(error) => {
// Handle error
console.log(error);
}
);
window.Camera.getPhoto({quality: 50,
destinationType: window.Camera.DestinationType.FILE_URI,
sourceType: window.Camera.PictureSourceType.CAMERA,
encodingType: window.Camera.EncodingType.JPEG,
mediaType: window.Camera.MediaType.PICTURE,
}).then(
function (fileUri) {
console.log(fileUri);
// fileUri will contain a path that can passed to the Filesystem API
// to read the raw data of the image, copy the picture or save it somewhere
// if desired (or pass destinationType: Camera.DestinationType.DATA_URL to getPicture)
},
(error) => {
// Handle error
console.log(error);
}
);
(<any>window).Camera.getPhoto({
quality: 50,
destinationType: (window).Camera.DestinationType.FILE_URI,
sourceType: (window).Camera.PictureSourceType.CAMERA,
encodingType: (window).Camera.EncodingType.JPEG,
mediaType: (window).Camera.MediaType.PICTURE,
}).then(
function (fileUri) {
console.log(fileUri);
// fileUri will contain a path that can passed to the Filesystem API
// to read the raw data of the image, copy the picture or save it somewhere
// if desired (or pass destinationType: Camera.DestinationType.DATA_URL to getPicture)
},
(error) => {
// Handle error
console.log(error);
}
);
window.Camera.getPhoto({quality: 50,
destinationType: window.Camera.DestinationType.FILE_URI,
sourceType: window.Camera.PictureSourceType.CAMERA,
encodingType: window.Camera.EncodingType.JPEG,
mediaType: window.Camera.MediaType.PICTURE,
}).then(
function (fileUri) {
console.log(fileUri);
// fileUri will contain a path that can passed to the Filesystem API
// to read the raw data of the image, copy the picture or save it somewhere
// if desired (or pass destinationType: Camera.DestinationType.DATA_URL to getPicture)
},
(error) => {
// Handle error
console.log(error);
}
);
getPhoto(options:CameraOptions): Promise<CameraPhoto>
Prompt the user to pick a photo from an album, or take a new photo with the camera.
Returns a Promise that resolves with the image file URI, or Base64 encoding of the image data, depending on CameraOptions, otherwise rejects with an error.
interface CameraOptions { // Whether to allow the user to crop or make small edits allowEdit ?: boolean, // Choose the camera to use (front- or back-facing). Default: Camera.Direction.BACK cameraDirection ?: Camera.Direction, // Whether to automatically rotate the image "up" to correct for orientation in portrait mode Default: true correctOrientation ?: boolean, // How the data should be returned. Can be 'DATA_URL', 'FILE_URI' or 'NATIVE_URI' destinationType ? : Camera.DestinationType, // Choose the returned image file's encoding. Default: Camera.EncodingType.JPEG encodingType ? : Camera.EncodingType, // Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. quality ?: number, // Save the image to the photo album on the device after capture. Default: false saveToPhotoAlbum ?: boolean, // The source to get the photo from. Default: Camera.PictureSourceType.CAMERA sourceType ?: Camera.PictureSourceType // Set the type of media to select from. Only works when PictureSourceType is PHOTOLIBRARY or SAVEDPHOTOALBUM mediaType ? : int, // Width in pixels to scale image. Must be used with targetHeight. Aspect ratio remains constant. targetWidth ? : int, // // Height in pixels to scale image. Must be used with targetWidth. Aspect ratio remains constant. targetHeight ? : int }
interface CameraPhoto { // The base64 encoded string representation of the image, if using CameraResultType.BASE64 base64String: string, // The url starting with ‘data:image/jpeg;base64,’ and the base64 encoded string representation of the image, if using CameraResultType.DATAURL dataUrl: string, // If using CameraResultType.URI, the path will contain a full, platform-specific file URL that can be read later using the Filsystem API path: string, // webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering webPath: string, // Exif data, if any, retrieved from the image exif: any, // The format of the image, ex: jpeg, png, gif. iOS and Android only support jpeg. Web supports jpeg and png. gif is only supported if using file input format: string }
enum Direction { BACK: 0, // Use the back-facing camera FRONT: 1 // Use the front-facing camera }
enum DestinationType { DATA_URL: 0, // Return base64 encoded string FILE_URI: 1, // Return file uri NATIVE_URI: 2 // Return native uri }
enum EncodingType { JPEG: 0, // Return JPEG encoded image PNG: 1 // Return PNG encoded image }
enum PictureSourceType { CAMERA: 1, // Take picture from camera PHOTOLIBRARY: 0, // Choose image from picture library SAVEDPHOTOALBUM: 2 // Choose image from picture library }
enum MediaType { ALLMEDIA: 0, // Allow selection from all media types PICTURE: 1, // DEFAULT value. Allow selection of still pictures only. Will return format specified via DestinationType VIDEO: 2 // Allow selection of video only, ONLY RETURNS URL }
enum CameraResultType { URI: "uri", BASE64: "base64", DATAURL: "dataUrl" }