2016-07-08 00:42:47 +02:00
import { Cordova , Plugin } from './plugin' ;
2015-11-25 11:44:58 -06:00
2016-04-25 05:41:48 -04:00
2016-02-08 16:30:01 -06:00
export interface CameraOptions {
2016-07-08 00:42:47 +02:00
/** Picture quality in range 0-100. Default is 50 */
quality? : number ;
/ * *
* Choose the format of the return value .
2016-10-17 10:34:16 +01:00
* Defined in Camera . DestinationType . Default is FILE_URI .
2016-10-05 17:33:31 -07:00
* DATA_URL : 0 , Return image as base64 - encoded string ,
* FILE_URI : 1 , Return image file URI ,
2016-07-08 00:42:47 +02:00
* NATIVE_URI : 2 Return image native URI
* ( e . g . , assets - library : // on iOS or content:// on Android)
* /
destinationType? : number ;
/ * *
* Set the source of the picture .
2016-10-17 10:34:16 +01:00
* Defined in Camera . PictureSourceType . Default is CAMERA .
2016-07-08 00:42:47 +02:00
* PHOTOLIBRARY : 0 ,
* CAMERA : 1 ,
* SAVEDPHOTOALBUM : 2
* /
sourceType? : number ;
/** Allow simple editing of image before selection. */
allowEdit? : boolean ;
/ * *
* Choose the returned image file ' s encoding .
2016-10-17 10:34:16 +01:00
* Defined in Camera . EncodingType . Default is JPEG
2016-07-08 00:42:47 +02:00
* JPEG : 0 Return JPEG encoded image
* PNG : 1 Return PNG encoded image
* /
encodingType? : number ;
/ * *
* Width in pixels to scale image . Must be used with targetHeight .
* Aspect ratio remains constant .
* /
targetWidth? : number ;
/ * *
* Height in pixels to scale image . Must be used with targetWidth .
* Aspect ratio remains constant .
* /
targetHeight? : number ;
/ * *
* Set the type of media to select from . Only works when PictureSourceType
2016-10-17 10:34:16 +01:00
* is PHOTOLIBRARY or SAVEDPHOTOALBUM . Defined in Camera . MediaType
2016-07-08 00:42:47 +02:00
* PICTURE : 0 allow selection of still pictures only . DEFAULT .
* Will return format specified via DestinationType
* VIDEO : 1 allow selection of video only , WILL ALWAYS RETURN FILE_URI
* ALLMEDIA : 2 allow selection from all media types
* /
mediaType? : number ;
/** Rotate the image to correct for the orientation of the device during capture. */
correctOrientation? : boolean ;
/** Save the image to the photo album on the device after capture. */
saveToPhotoAlbum? : boolean ;
/ * *
* Choose the camera to use ( front - or back - facing ) .
2016-10-17 10:34:16 +01:00
* Defined in Camera . Direction . Default is BACK .
2016-12-01 14:36:56 +00:00
* BACK : 0
* FRONT : 1
2016-07-08 00:42:47 +02:00
* /
cameraDirection? : number ;
/** iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions. */
popoverOptions? : CameraPopoverOptions ;
2016-02-08 16:30:01 -06:00
}
/ * *
* iOS - only parameters that specify the anchor element location and arrow direction
* of the popover when selecting images from an iPad ' s library or album .
* /
export interface CameraPopoverOptions {
2016-07-08 00:42:47 +02:00
x : number ;
y : number ;
width : number ;
height : number ;
/ * *
* Direction the arrow on the popover should point . Defined in Camera . PopoverArrowDirection
* Matches iOS UIPopoverArrowDirection constants .
* ARROW_UP : 1 ,
* ARROW_DOWN : 2 ,
* ARROW_LEFT : 4 ,
* ARROW_RIGHT : 8 ,
* ARROW_ANY : 15
* /
arrowDir : number ;
2016-02-08 16:30:01 -06:00
}
2016-01-25 16:20:36 -06:00
/ * *
2016-02-22 16:20:00 -05:00
* @name Camera
* @description
2016-01-25 16:20:36 -06:00
* Take a photo or capture video .
*
2016-03-15 15:39:09 +00:00
* Requires { @link module :driftyco / ionic - native } and the Cordova plugin : ` cordova-plugin-camera ` . For more info , please see the [ Cordova Camera Plugin Docs ] ( https : //github.com/apache/cordova-plugin-camera).
2016-01-25 16:20:36 -06:00
*
* @usage
2016-07-20 17:17:09 +02:00
* ` ` ` typescript
* import { Camera } from 'ionic-native' ;
*
2016-07-08 00:42:47 +02:00
*
2016-01-25 16:20:36 -06:00
* Camera . getPicture ( options ) . then ( ( imageData ) = > {
* // imageData is either a base64 encoded string or a file URI
* // If it's base64:
2016-07-20 17:17:09 +02:00
* let base64Image = 'data:image/jpeg;base64,' + imageData ;
2016-01-25 16:20:36 -06:00
* } , ( err ) = > {
2016-07-20 17:17:09 +02:00
* // Handle error
2016-01-25 16:20:36 -06:00
* } ) ;
* ` ` `
2016-09-27 10:46:41 -04:00
* @interfaces
* CameraOptions
* CameraPopoverOptions
2016-01-25 16:20:36 -06:00
* /
2015-11-28 18:26:55 -06:00
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'Camera' ,
2015-11-28 16:17:04 -06:00
plugin : 'cordova-plugin-camera' ,
2016-02-22 16:20:00 -05:00
pluginRef : 'navigator.camera' ,
2016-03-14 13:38:35 -04:00
repo : 'https://github.com/apache/cordova-plugin-camera' ,
2016-04-29 23:56:49 -04:00
platforms : [ 'Android' , 'BlackBerry' , 'Browser' , 'Firefox' , 'FireOS' , 'iOS' , 'Windows' , 'Windows Phone 8' , 'Ubuntu' ]
2015-11-28 18:26:55 -06:00
} )
export class Camera {
2016-12-06 08:02:00 -05:00
2016-04-25 05:41:48 -04:00
/ * *
2016-07-08 15:19:13 -04:00
* @private
2016-04-25 05:41:48 -04:00
* @enum { number }
* /
2016-11-29 13:33:11 -05:00
static DestinationType = {
2016-04-25 05:41:48 -04:00
/** Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI or NATIVE_URI if possible */
DATA_URL : 0 ,
/** Return file uri (content://media/external/images/media/2 for Android) */
FILE_URI : 1 ,
/** Return native uri (eg. asset-library://... for iOS) */
NATIVE_URI : 2
} ;
/ * *
2016-07-08 15:19:13 -04:00
* @private
2016-04-25 05:41:48 -04:00
* @enum { number }
* /
2016-11-29 13:33:11 -05:00
static EncodingType = {
2016-04-25 05:41:48 -04:00
/** Return JPEG encoded image */
JPEG : 0 ,
/** Return PNG encoded image */
PNG : 1
} ;
/ * *
2016-07-08 15:19:13 -04:00
* @private
2016-04-25 05:41:48 -04:00
* @enum { number }
* /
2016-11-29 13:33:11 -05:00
static MediaType = {
2016-04-25 05:41:48 -04:00
/** Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType */
PICTURE : 0 ,
/** Allow selection of video only, ONLY RETURNS URL */
VIDEO : 1 ,
/** Allow selection from all media types */
2016-07-08 00:42:47 +02:00
ALLMEDIA : 2
2016-04-25 05:41:48 -04:00
} ;
/ * *
2016-07-08 15:19:13 -04:00
* @private
2016-04-25 05:41:48 -04:00
* @enum { number }
* /
2016-11-29 13:33:11 -05:00
static PictureSourceType = {
2016-04-25 05:41:48 -04:00
/** Choose image from picture library (same as SAVEDPHOTOALBUM for Android) */
2016-07-08 00:42:47 +02:00
PHOTOLIBRARY : 0 ,
2016-04-25 05:41:48 -04:00
/** Take picture from camera */
2016-07-08 00:42:47 +02:00
CAMERA : 1 ,
2016-04-25 05:41:48 -04:00
/** Choose image from picture library (same as PHOTOLIBRARY for Android) */
2016-07-08 00:42:47 +02:00
SAVEDPHOTOALBUM : 2
2016-04-25 05:41:48 -04:00
} ;
/ * *
2016-07-08 15:19:13 -04:00
* @private
2016-04-25 05:41:48 -04:00
* Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover .
* @enum { number }
* /
2016-11-29 13:33:11 -05:00
static PopoverArrowDirection = {
2016-07-08 00:42:47 +02:00
ARROW_UP : 1 ,
ARROW_DOWN : 2 ,
ARROW_LEFT : 4 ,
ARROW_RIGHT : 8 ,
ARROW_ANY : 15
2016-04-25 05:41:48 -04:00
} ;
/ * *
2016-07-08 15:19:13 -04:00
* @private
2016-04-25 05:41:48 -04:00
* @enum { number }
* /
2016-11-29 13:33:11 -05:00
static Direction = {
2016-04-25 05:41:48 -04:00
/** Use the back-facing camera */
BACK : 0 ,
/** Use the front-facing camera */
FRONT : 1
} ;
2016-07-18 14:04:49 +02:00
/ * *
* Take a picture or video , or load one from the library .
2016-12-01 09:50:21 -06:00
* @param { CameraOptions ? } options optional . Options that you want to pass to the camera . Encoding type , quality , etc . Platform - specific quirks are described in the [ Cordova plugin docs ] ( https : //github.com/apache/cordova-plugin-camera#cameraoptions-errata-).
2016-11-29 16:40:50 -06:00
* @returns { Promise < any > } Returns a Promise that resolves with Base64 encoding of the image data , or the image file URI , depending on cameraOptions , otherwise rejects with an error .
2016-07-18 14:04:49 +02:00
* /
@Cordova ( {
callbackOrder : 'reverse'
} )
2016-08-11 08:29:14 -03:00
static getPicture ( options? : CameraOptions ) : Promise < any > { return ; }
2016-02-08 16:30:01 -06:00
2016-07-18 14:04:49 +02:00
/ * *
* Remove intermediate image files that are kept in temporary storage after calling camera . getPicture .
* Applies only when the value of Camera . sourceType equals Camera . PictureSourceType . CAMERA and the Camera . destinationType equals Camera . DestinationType . FILE_URI .
2016-11-29 16:40:50 -06:00
* @returns { Promise < any > }
2016-07-18 14:04:49 +02:00
* /
@Cordova ( {
platforms : [ 'iOS' ]
} )
2016-09-19 18:14:51 -04:00
static cleanup ( ) : Promise < any > { return ; } ;
2016-02-08 16:30:01 -06:00
2016-07-18 14:04:49 +02:00
}