Camera

Improve this doc

$ ionic plugin add cordova-plugin-camera

Repo: https://github.com/apache/cordova-plugin-camera

Take a photo or capture video.

Requires ionic-native and the Cordova plugin: cordova-plugin-camera. For more info, please see the Cordova Camera Plugin Docs.

Supported platforms

Usage

import { Camera } from 'ionic-native';


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) => {
 // Handle error
});

Static Members

getPicture(options)

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

Param Type Details
options CameraOptions

optional. Options that you want to pass to the camera. Encoding type, quality, etc. Platform-specific quirks are described in the Cordova plugin docs.

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.

cleanup()

Platforms: iOS 

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>

CameraOptions

Param Type Details
quality
(optional)
number

Picture quality in range 0-100. Default is 50

destinationType
(optional)
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, FILE_URI : 1, Return image file URI, NATIVE_URI : 2 Return image native URI (e.g., assets-library:// on iOS or content:// on Android)

sourceType
(optional)
number

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

allowEdit
(optional)
boolean

Allow simple editing of image before selection.

encodingType
(optional)
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

targetWidth
(optional)
number

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

targetHeight
(optional)
number

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

mediaType
(optional)
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

correctOrientation
(optional)
boolean

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

saveToPhotoAlbum
(optional)
boolean

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

cameraDirection
(optional)
number

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

popoverOptions
(optional)
CameraPopoverOptions

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

CameraPopoverOptions

Param Type Details
x number
y number
width number
height number
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

API

Native

General