2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
2017-04-27 00:36:12 -04:00
import { Cordova , Plugin , IonicNativePlugin } from '@ionic-native/core' ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
export interface CameraPreviewDimensions {
/** The width of the camera preview, default to window.screen.width */
width? : number ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
/** The height of the camera preview, default to window.screen.height */
height? : number ;
}
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
export interface CameraPreviewOptions {
/** The left edge in pixels, default 0 */
x? : number ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
/** The top edge in pixels, default 0 */
y? : number ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
/** The width in pixels, default window.screen.width */
width? : number ;
/** The height in pixels, default window.screen.height */
height? : number ;
2016-07-17 10:50:18 +02:00
2017-03-20 21:10:04 +01:00
/** Choose the camera to use 'front' or 'rear', default 'front' */
camera? : string ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
/** Tap to take a photo, default true (picture quality by default : 85) */
tapPhoto? : boolean ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
/** Preview box drag across the screen, default 'false' */
previewDrag? : boolean ;
2016-12-06 08:02:00 -05:00
2017-03-20 21:10:04 +01:00
/** Preview box to the back of the webview (true => back, false => front) , default false */
toBack? : boolean ;
/** Alpha channel of the preview box, float, [0,1], default 1 */
alpha? : number ;
2017-12-08 14:05:59 -06:00
/** Tap to set specific focus point. Note, this assumes the camera is full-screen. default false */
tapToFocus? : boolean ;
2017-03-20 21:10:04 +01:00
}
2017-03-20 16:38:14 -04:00
export interface CameraPreviewPictureOptions {
2017-04-30 20:36:22 +02:00
/** The width in pixels, default 0 */
width? : number ;
/** The height in pixels, default 0 */
height? : number ;
/** The picture quality, 0 - 100, default 85 */
quality? : number ;
2016-07-17 10:50:18 +02:00
}
/**
2017-01-10 07:41:44 -05:00
* @beta
2017-03-20 16:38:14 -04:00
* @name Camera Preview
2016-07-17 10:50:18 +02:00
* @description
* Showing camera preview in HTML
2017-03-20 16:38:14 -04:00
*
2017-03-20 21:10:04 +01:00
* Requires Cordova plugin: `https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git`. For more info, please see the [Cordova Camera Preview docs](https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview).
2016-07-17 10:50:18 +02:00
*
2016-09-06 23:12:35 -04:00
* @usage
2017-03-20 21:10:04 +01:00
* ```typescript
2017-05-12 04:50:27 -03:00
* import { CameraPreview, CameraPreviewPictureOptions, CameraPreviewOptions, CameraPreviewDimensions } from '@ionic-native/camera-preview';
2017-03-20 16:38:14 -04:00
*
* constructor(private cameraPreview: CameraPreview) { }
*
* ...
2016-09-06 23:12:35 -04:00
*
2017-03-20 21:10:04 +01:00
* // camera options (Size and location). In the following example, the preview uses the rear camera and display the preview in the back of the webview
2017-03-20 16:38:14 -04:00
* const cameraPreviewOpts: CameraPreviewOptions = {
2017-03-20 21:10:04 +01:00
* x: 0,
* y: 0,
* width: window.screen.width,
* height: window.screen.height,
* camera: 'rear',
* tapPhoto: true,
* previewDrag: true,
* toBack: true,
* alpha: 1
2016-09-06 23:12:35 -04:00
* };
*
* // start camera
2017-03-20 16:38:14 -04:00
* this.cameraPreview.startCamera(cameraPreviewOpts).then(
2017-03-20 21:10:04 +01:00
* (res) => {
* console.log(res)
* },
* (err) => {
* console.log(err)
* });
2016-09-06 23:12:35 -04:00
*
2017-03-20 16:38:14 -04:00
* // Set the handler to run every time we take a picture
* this.cameraPreview.setOnPictureTakenHandler().subscribe((result) => {
* console.log(result);
* // do something with the result
* });
*
*
2017-03-20 21:10:04 +01:00
* // picture options
2017-05-12 04:50:27 -03:00
* const pictureOpts: CameraPreviewPictureOptions = {
2017-03-20 21:10:04 +01:00
* width: 1280,
* height: 1280,
* quality: 85
* }
2016-09-06 23:12:35 -04:00
*
* // take a picture
2017-03-20 16:38:14 -04:00
* this.cameraPreview.takePicture(this.pictureOpts).then((imageData) => {
2017-03-20 21:10:04 +01:00
* this.picture = 'data:image/jpeg;base64,' + imageData;
2017-03-20 16:38:14 -04:00
* }, (err) => {
2017-03-20 21:10:04 +01:00
* console.log(err);
* this.picture = 'assets/img/test.jpg';
2016-09-06 23:12:35 -04:00
* });
*
2017-03-20 16:38:14 -04:00
*
2016-09-06 23:12:35 -04:00
* // Switch camera
2017-03-20 16:38:14 -04:00
* this.cameraPreview.switchCamera();
2016-09-06 23:12:35 -04:00
*
* // set color effect to negative
2017-03-20 16:38:14 -04:00
* this.cameraPreview.setColorEffect('negative');
2016-09-06 23:12:35 -04:00
*
* // Stop the camera preview
2017-03-20 16:38:14 -04:00
* this.cameraPreview.stopCamera();
2016-09-06 23:12:35 -04:00
*
* ```
*
2016-12-06 08:58:38 -05:00
* @interfaces
2017-03-20 21:10:04 +01:00
* CameraPreviewOptions
2017-03-20 16:38:14 -04:00
* CameraPreviewPictureOptions
2017-03-20 21:10:04 +01:00
* CameraPreviewDimensions
2016-07-17 10:50:18 +02:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'CameraPreview' ,
2016-11-18 14:30:06 -08:00
plugin : 'cordova-plugin-camera-preview' ,
2017-03-20 21:10:04 +01:00
pluginRef : 'CameraPreview' ,
2016-11-18 14:30:06 -08:00
repo : 'https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview' ,
2016-07-17 10:50:18 +02:00
platforms : [ 'Android' , 'iOS' ]
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2017-04-27 00:36:12 -04:00
export class CameraPreview extends IonicNativePlugin {
2016-07-17 10:50:18 +02:00
2017-04-30 19:21:28 +02:00
FOCUS_MODE = {
FIXED : 'fixed' ,
AUTO : 'auto' ,
CONTINUOUS : 'continuous' , // IOS Only
CONTINUOUS_PICTURE : 'continuous-picture' , // Android Only
CONTINUOUS_VIDEO : 'continuous-video' , // Android Only
EDOF : 'edof' , // Android Only
INFINITY : 'infinity' , // Android Only
MACRO : 'macro' // Android Only
} ;
EXPOSURE_MODE = {
2017-04-18 07:15:15 +02:00
LOCK : 'lock' , // IOS Only
AUTO : 'auto' , // IOS Only
CONTINUOUS : 'continuous' ,
CUSTOM : 'custom'
} ;
FLASH_MODE = {
OFF : 'off' ,
ON : 'on' ,
AUTO : 'auto' ,
RED_EYE : 'red-eye' ,
TORCH : 'torch' // Android Only
} ;
COLOR_EFFECT = {
AQUA : 'aqua' , // Android Only
BLACKBOARD : 'blackboard' , // Android Only
MONO : 'mono' ,
NEGATIVE : 'negative' ,
NONE : 'none' ,
POSTERIZE : 'posterize' ,
SEPIA : 'sepia' ,
SOLARIZE : 'solarize' , // Android Only
WHITEBOARD : 'whiteboard' // Android Only
} ;
CAMERA_DIRECTION = {
BACK : 'back' ,
FRONT : 'front'
} ;
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
* Starts the camera preview instance.
2017-03-20 21:10:04 +01:00
* @param {CameraPreviewOptions} options
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
@Cordova ( {
2017-03-20 21:10:04 +01:00
successIndex : 1 ,
errorIndex : 2
2016-07-17 10:50:18 +02:00
} )
2017-03-20 16:38:14 -04:00
startCamera ( options : CameraPreviewOptions ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 21:10:04 +01:00
* Stops the camera preview instance. (iOS & Android)
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
2017-04-18 07:15:15 +02:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
stopCamera ( ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
* Switch from the rear camera and front camera, if available.
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
2017-04-18 07:15:15 +02:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
switchCamera ( ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
* Hide the camera preview box.
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
2017-04-18 07:15:15 +02:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
hide ( ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
* Show the camera preview box.
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
2017-04-18 07:15:15 +02:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
show ( ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
* Take the picture (base64)
2017-03-23 15:37:17 -04:00
* @param [options] {CameraPreviewPictureOptions} size and quality of the picture to take
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
@Cordova ( {
2017-03-20 21:10:04 +01:00
successIndex : 1 ,
errorIndex : 2
2016-07-17 10:50:18 +02:00
} )
2017-03-20 16:38:14 -04:00
takePicture ( options? : CameraPreviewPictureOptions ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
*
* Set camera color effect.
2017-03-20 21:10:04 +01:00
* @static
* @param {string} effect name : 'none' (iOS & Android), 'aqua' (Android), 'blackboard' (Android), 'mono' (iOS & Android), 'negative' (iOS & Android), 'posterize' (iOS & Android), 'sepia' (iOS & Android), 'solarize' (Android) or 'whiteboard' (Android)
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
@Cordova ( {
2017-03-20 21:10:04 +01:00
successIndex : 1 ,
errorIndex : 2
2016-07-17 10:50:18 +02:00
} )
2017-03-20 16:38:14 -04:00
setColorEffect ( effect : string ) : Promise < any > { return ; }
2016-11-23 08:16:02 -05:00
/**
2017-03-20 21:10:04 +01:00
* Set the zoom (Android)
2017-03-24 15:17:35 -04:00
* @param [zoom] {number} Zoom value
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2016-11-23 08:16:02 -05:00
*/
@Cordova ( {
2017-03-20 21:10:04 +01:00
successIndex : 1 ,
errorIndex : 2
2016-11-23 08:16:02 -05:00
} )
2017-03-20 16:38:14 -04:00
setZoom ( zoom? : number ) : Promise < any > { return ; }
2017-03-20 21:10:04 +01:00
2017-04-30 20:36:22 +02:00
/**
* Get the maximum zoom (Android)
* @return {Promise<any>}
*/
2017-04-18 07:15:15 +02:00
@Cordova ( )
getMaxZoom ( ) : Promise < any > { return ; }
/**
* Get current zoom (Android)
* @return {Promise<any>}
*/
@Cordova ( )
getZoom ( ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
/**
2017-03-20 16:38:14 -04:00
* Set the preview Size
2017-03-24 15:17:35 -04:00
* @param [dimensions] {CameraPreviewDimensions}
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2016-07-17 10:50:18 +02:00
*/
@Cordova ( {
2017-03-20 21:10:04 +01:00
successIndex : 1 ,
2017-04-18 07:15:15 +02:00
errorIndex : 2
2016-07-17 10:50:18 +02:00
} )
2017-03-20 16:38:14 -04:00
setPreviewSize ( dimensions? : CameraPreviewDimensions ) : Promise < any > { return ; }
2016-12-06 08:02:00 -05:00
2017-04-30 19:21:28 +02:00
/**
* Get focus mode
* @return {Promise<any>}
*/
@Cordova ( )
getFocusMode ( ) : Promise < any > { return ; }
/**
* Set the focus mode
* @param [focusMode] {string} 'fixed', 'auto', 'continuous-picture', 'continuous-video' (iOS & Android), 'edof', 'infinity', 'macro' (Android Only)
* @return {Promise<any>}
*/
@Cordova ( {
successIndex : 1 ,
errorIndex : 2
} )
setFocusMode ( focusMode? : string ) : Promise < any > { return ; }
/**
* Get supported focus modes
* @return {Promise<any>}
*/
@Cordova ( )
getSupportedFocusModes ( ) : Promise < any > { return ; }
/**
* Get the current flash mode
* @return {Promise<any>}
*/
@Cordova ( )
getFlashMode ( ) : Promise < any > { return ; }
2017-03-20 21:10:04 +01:00
/**
2017-03-20 16:38:14 -04:00
* Set the flashmode
2017-03-24 15:17:35 -04:00
* @param [flashMode] {string} 'off' (iOS & Android), 'on' (iOS & Android), 'auto' (iOS & Android), 'torch' (Android)
2017-03-20 16:38:14 -04:00
* @return {Promise<any>}
2017-03-20 21:10:04 +01:00
*/
@Cordova ( {
successIndex : 1 ,
errorIndex : 2
} )
2017-03-20 16:38:14 -04:00
setFlashMode ( flashMode? : string ) : Promise < any > { return ; }
2017-04-18 07:15:15 +02:00
/**
2017-04-30 19:21:28 +02:00
* Get supported flash modes
2017-04-18 07:15:15 +02:00
* @return {Promise<any>}
*/
@Cordova ( )
2017-04-30 19:21:28 +02:00
getSupportedFlashModes ( ) : Promise < any > { return ; }
2017-04-18 07:15:15 +02:00
/**
2017-04-30 19:21:28 +02:00
* Get supported picture sizes
2017-04-18 07:15:15 +02:00
* @return {Promise<any>}
*/
@Cordova ( )
2017-04-30 19:21:28 +02:00
getSupportedPictureSizes ( ) : Promise < any > { return ; }
2017-04-18 07:15:15 +02:00
/**
* Get exposure mode
* @return {Promise<any>}
*/
@Cordova ( )
getExposureMode ( ) : Promise < any > { return ; }
/**
* Get exposure modes
* @return {Promise<any>}
*/
@Cordova ( )
getExposureModes ( ) : Promise < any > { return ; }
/**
* Set exposure mode
* @param [lock] {string}
* @return {Promise<any>}
*/
@Cordova ( {
successIndex : 1 ,
errorIndex : 2
} )
setExposureMode ( lock? : string ) : Promise < any > { return ; }
/**
* Get exposure compensation (Android)
* @return {Promise<any>}
*/
@Cordova ( )
getExposureCompensation ( ) : Promise < any > { return ; }
/**
* Set exposure compensation (Android)
* @param [exposureCompensation] {number}
* @return {Promise<any>}
*/
@Cordova ( {
successIndex : 1 ,
errorIndex : 2
} )
setExposureCompensation ( exposureCompensation? : number ) : Promise < any > { return ; }
/**
* Get exposure compensation range (Android)
* @return {Promise<any>}
*/
@Cordova ( )
getExposureCompensationRange ( ) : Promise < any > { return ; }
2017-05-07 16:17:00 +02:00
/**
* Set specific focus point. Note, this assumes the camera is full-screen.
* @param xPoint {number}
* @param yPoint {number}
* @return {Promise<any>}
*/
@Cordova ( )
tapToFocus ( xPoint : number , yPoint : number ) : Promise < any > { return ; }
2016-07-17 10:50:18 +02:00
}