2016-07-08 06:42:47 +08:00
import { Cordova , Plugin } from './plugin' ;
2015-11-26 01:44:58 +08:00
2016-04-25 17:41:48 +08:00
2016-02-09 06:30:01 +08:00
export interface CameraOptions {
2016-07-08 06:42:47 +08:00
/** Picture quality in range 0-100. Default is 50 */
quality? : number ;
/ * *
* Choose the format of the return value .
* Defined in navigator . camera . DestinationType . Default is FILE_URI .
* DATA_URL : 0 , Return image as base64 - encoded string
* FILE_URI : 1 , Return image file URI
* 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 .
* Defined in navigator . camera . PictureSourceType . Default is CAMERA .
* PHOTOLIBRARY : 0 ,
* CAMERA : 1 ,
* SAVEDPHOTOALBUM : 2
* /
sourceType? : number ;
/** Allow simple editing of image before selection. */
allowEdit? : boolean ;
/ * *
* Choose the returned image file ' s encoding .
* Defined in navigator . camera . EncodingType . Default is JPEG
* 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
* is PHOTOLIBRARY or SAVEDPHOTOALBUM . Defined in nagivator . camera . MediaType
* 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 ) .
* Defined in navigator . camera . Direction . Default is BACK .
* FRONT : 0
* BACK : 1
* /
cameraDirection? : number ;
/** iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions. */
popoverOptions? : CameraPopoverOptions ;
2016-02-09 06:30:01 +08: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 06:42:47 +08: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-09 06:30:01 +08:00
}
2016-01-26 06:20:36 +08:00
/ * *
2016-02-23 05:20:00 +08:00
* @name Camera
* @description
2016-01-26 06:20:36 +08:00
* Take a photo or capture video .
*
2016-03-15 23:39:09 +08: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-26 06:20:36 +08:00
*
* @usage
* ` ` ` js
2016-03-15 23:39:09 +08:00
* import { Camera } from 'ionic-native' ;
2016-07-08 06:42:47 +08:00
*
2016-01-26 06:20:36 +08:00
* Camera . getPicture ( options ) . then ( ( imageData ) = > {
* // imageData is either a base64 encoded string or a file URI
* // If it's base64:
* let base64Image = "data:image/jpeg;base64," + imageData ;
* } , ( err ) = > {
* } ) ;
* ` ` `
* /
2015-11-29 08:26:55 +08:00
@Plugin ( {
2015-11-29 06:17:04 +08:00
plugin : 'cordova-plugin-camera' ,
2016-02-23 05:20:00 +08:00
pluginRef : 'navigator.camera' ,
2016-03-15 01:38:35 +08:00
repo : 'https://github.com/apache/cordova-plugin-camera' ,
2016-04-30 11:56:49 +08:00
platforms : [ 'Android' , 'BlackBerry' , 'Browser' , 'Firefox' , 'FireOS' , 'iOS' , 'Windows' , 'Windows Phone 8' , 'Ubuntu' ]
2015-11-29 08:26:55 +08:00
} )
export class Camera {
2016-02-09 06:30:01 +08:00
/ * *
* Take a picture or video , or load one from the library .
2016-07-09 03:19:13 +08:00
* @param { CameraOptions } options Options that you want to pass to the camera . Encoding type , quality , etc .
* @return { Promise } 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-02-09 06:30:01 +08:00
* /
2015-11-29 08:26:55 +08:00
@Cordova ( {
2015-11-30 09:54:45 +08:00
callbackOrder : 'reverse'
2015-11-29 08:26:55 +08:00
} )
2016-04-30 11:56:49 +08:00
static getPicture ( options : CameraOptions ) : Promise < any > { return ; }
2015-11-29 06:17:04 +08:00
2016-02-09 06:30:01 +08: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 .
* @return Returns a Promise
* /
2016-03-15 01:54:35 +08:00
@Cordova ( {
platforms : [ 'iOS' ]
} )
2016-04-30 11:56:49 +08:00
static cleanup() { } ;
2016-04-25 17:41:48 +08:00
/ * *
2016-07-09 03:19:13 +08:00
* @private
2016-04-25 17:41:48 +08:00
* @enum { number }
* /
static DestinationType = {
/** 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-09 03:19:13 +08:00
* @private
2016-04-25 17:41:48 +08:00
* @enum { number }
* /
static EncodingType = {
/** Return JPEG encoded image */
JPEG : 0 ,
/** Return PNG encoded image */
PNG : 1
} ;
/ * *
2016-07-09 03:19:13 +08:00
* @private
2016-04-25 17:41:48 +08:00
* @enum { number }
* /
static MediaType = {
/** 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 06:42:47 +08:00
ALLMEDIA : 2
2016-04-25 17:41:48 +08:00
} ;
/ * *
2016-07-09 03:19:13 +08:00
* @private
2016-04-25 17:41:48 +08:00
* @enum { number }
* /
static PictureSourceType = {
/** Choose image from picture library (same as SAVEDPHOTOALBUM for Android) */
2016-07-08 06:42:47 +08:00
PHOTOLIBRARY : 0 ,
2016-04-25 17:41:48 +08:00
/** Take picture from camera */
2016-07-08 06:42:47 +08:00
CAMERA : 1 ,
2016-04-25 17:41:48 +08:00
/** Choose image from picture library (same as PHOTOLIBRARY for Android) */
2016-07-08 06:42:47 +08:00
SAVEDPHOTOALBUM : 2
2016-04-25 17:41:48 +08:00
} ;
/ * *
2016-07-09 03:19:13 +08:00
* @private
2016-04-25 17:41:48 +08:00
* Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover .
* @enum { number }
* /
static PopoverArrowDirection = {
2016-07-08 06:42:47 +08:00
ARROW_UP : 1 ,
ARROW_DOWN : 2 ,
ARROW_LEFT : 4 ,
ARROW_RIGHT : 8 ,
ARROW_ANY : 15
2016-04-25 17:41:48 +08:00
} ;
/ * *
2016-07-09 03:19:13 +08:00
* @private
2016-04-25 17:41:48 +08:00
* @enum { number }
* /
static Direction = {
/** Use the back-facing camera */
BACK : 0 ,
/** Use the front-facing camera */
FRONT : 1
} ;
2015-11-26 01:44:58 +08:00
}
2016-02-09 06:30:01 +08:00