Camera

v4.0.3

Contents

Installation

In order to use Ionic Enterprise Edition plugins you should make sure you're using the Ionic Enterprise Cordova CLI as the regular version can have issues with scoped plugins.

npm uninstall -g cordovanpm install -g @ionic-enterprise/cordova

Once you've installed the Ionic Enterprise Cordova CLI you can install the plugin.

ionic enterprise register --key=YOURPRODUCTKEYionic cordova plugin add @ionic-enterprise/camera

Index

Enumerations

Classes

Interfaces


Enumerations

DestinationType

DestinationType:

DATA_URL

DATA_URL: = 0


FILE_URL

FILE_URL: = 1


NATIVE_URI

NATIVE_URI: = 2



Direction

Direction:

BACK

BACK: = 0


FRONT

FRONT: = 1



EncodingType

EncodingType:

JPEG

JPEG: = 0


PNG

PNG: = 1



MediaType

MediaType:

ALLMEDIA

ALLMEDIA: = 2


PICTURE

PICTURE: = 0


VIDEO

VIDEO: = 1



PictureSourceType

PictureSourceType:

CAMERA

CAMERA: = 1


PHOTOLIBRARY

PHOTOLIBRARY: = 0


SAVEDPHOTOALBUM

SAVEDPHOTOALBUM: = 2



PopoverArrowDirection

PopoverArrowDirection:

ARROW_ANY

ARROW_ANY: = 5


ARROW_DOWN

ARROW_DOWN: = 2


ARROW_LEFT

ARROW_LEFT: = 3


ARROW_RIGHT

ARROW_RIGHT: = 4


ARROW_UP

ARROW_UP: = 1



Classes

Camera

Camera:

name: Camera

description: Take a photo or capture video.

[Warning] Since IOS 10 the camera requires permissions to be placed in your config.xml add

<config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist"> <string>You can take photos</string> </config-file>

inside of the <platform name='ios> section

usage:

import { Camera, CameraOptions } from '@ionic-enterprise/camera/ngx'; constructor(private camera: Camera) { } ... const options: CameraOptions = { quality: 100, destinationType: this.camera.DestinationType.FILE_URI, encodingType: this.camera.EncodingType.JPEG, mediaType: this.camera.MediaType.PICTURE } this.camera.getPicture(options).then((imageData) => { // imageData is either a base64 encoded string or a file URI // If it's base64 (DATA_URL): let base64Image = 'data:image/jpeg;base64,' + imageData; }, (err) => { // Handle error });

interfaces: CameraOptions CameraPopoverOptions

DestinationType

● DestinationType: object

Constant for possible destination types

Type declaration

DATA_URL: number

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

FILE_URI: number

Return file uri (content://media/external/images/media/2 for Android)

NATIVE_URI: number

Return native uri (eg. asset-library://... for iOS)


Direction

● Direction: object

Convenience constant

Type declaration

BACK: number

Use the back-facing camera

FRONT: number

Use the front-facing camera


EncodingType

● EncodingType: object

Convenience constant

Type declaration

JPEG: number

Return JPEG encoded image

PNG: number

Return PNG encoded image


MediaType

● MediaType: object

Convenience constant

Type declaration

ALLMEDIA: number

Allow selection from all media types

PICTURE: number

Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType

VIDEO: number

Allow selection of video only, ONLY RETURNS URL


PictureSourceType

● PictureSourceType: object

Convenience constant

Type declaration

CAMERA: number

Take picture from camera

PHOTOLIBRARY: number

Choose image from picture library (same as SAVEDPHOTOALBUM for Android)

SAVEDPHOTOALBUM: number

Choose image from picture library (same as PHOTOLIBRARY for Android)


PopoverArrowDirection

● PopoverArrowDirection: object

Convenience constant

Type declaration

ARROW_ANY: number

ARROW_DOWN: number

ARROW_LEFT: number

ARROW_RIGHT: number

ARROW_UP: number


cleanup

cleanup(): Promise<any>

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.

Returns: Promise<any>


getPicture

getPicture(options?: *CameraOptions*): Promise<any>

Take a picture or video, or load one from the library.

Parameters:

Name Type
Optional options CameraOptions

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.



Interfaces

CameraOptions

CameraOptions:

<Optional> allowEdit

● allowEdit: boolean

Allow simple editing of image before selection.


<Optional> cameraDirection

● cameraDirection: number

Choose the camera to use (front- or back-facing). Defined in Camera.Direction. Default is BACK. BACK: 0 FRONT: 1


<Optional> correctOrientation

● correctOrientation: boolean

Rotate the image to correct for the orientation of the device during capture.


<Optional> destinationType

● destinationType: number

Choose the format of the return value. Defined in Camera.DestinationType. Default is FILE_URI. DATA_URL : 0, Return image as 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), FILE_URI : 1, Return image file URI, NATIVE_URI : 2 Return image native URI (e.g., assets-library:// on iOS or content:// on Android)


<Optional> encodingType

● encodingType: number

Choose the returned image file's encoding. Defined in Camera.EncodingType. Default is JPEG JPEG : 0 Return JPEG encoded image PNG : 1 Return PNG encoded image


<Optional> mediaType

● mediaType: number

Set the type of media to select from. Only works when PictureSourceType is PHOTOLIBRARY or SAVEDPHOTOALBUM. Defined in 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


<Optional> popoverOptions

● popoverOptions: *CameraPopoverOptions*

iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions.


<Optional> quality

● quality: number

Picture quality in range 0-100. Default is 50


<Optional> saveToPhotoAlbum

● saveToPhotoAlbum: boolean

Save the image to the photo album on the device after capture.


<Optional> sourceType

● sourceType: number

Set the source of the picture. Defined in Camera.PictureSourceType. Default is CAMERA. PHOTOLIBRARY : 0, CAMERA : 1, SAVEDPHOTOALBUM : 2


<Optional> targetHeight

● targetHeight: number

Height in pixels to scale image. Must be used with targetWidth. Aspect ratio remains constant.


<Optional> targetWidth

● targetWidth: number

Width in pixels to scale image. Must be used with targetHeight. Aspect ratio remains constant.



CameraPopoverOptions

CameraPopoverOptions:

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.

arrowDir

● arrowDir: 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


height

● height: number


width

● width: number


x

● x: number


y

● y: number



Other Versions