Framework v4 BETA

Camera

Take a photo or capture video.

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

[Warning] Since IOS 10 the camera requires permissions to be placed in your config.xml add 'You can take photos inside of the <platform name='ios> section

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

Installation

  1. Install the Cordova and Ionic Native plugins:
    shell
    $ ionic cordova plugin add cordova-plugin-camera
    $ npm install --save @ionic-native/[email protected]
    
  2. Add this plugin to your app's module

Supported Platforms

  • Android
  • Browser
  • iOS
  • Windows

Usage

typescript
import { Camera, CameraOptions } from '@ionic-native/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
});


Instance Members

DestinationType

Constant for possible destination types


Direction

Convenience constant


EncodingType

Convenience constant


MediaType

Convenience constant


PictureSourceType

Convenience constant


PopoverArrowDirection

Convenience constant


cleanup

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.


getPicture

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

Parameters

options

Type: CameraOptions
See CameraOptions table below optional


CameraOptions

allowEdit

Type: intrinsic
Allow simple editing of image before selection. optional

cameraDirection

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

correctOrientation

Type: intrinsic
Rotate the image to correct for the orientation of the device during capture. optional

destinationType

Type: intrinsic
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

Type: intrinsic
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

Type: intrinsic
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

Type: reference
iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions. optional

quality

Type: intrinsic
Picture quality in range 0-100. Default is 50 optional

saveToPhotoAlbum

Type: intrinsic
Save the image to the photo album on the device after capture. optional

sourceType

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

targetHeight

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

targetWidth

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

CameraPopoverOptions

arrowDir

Type: intrinsic
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

Type: intrinsic
undefined

width

Type: intrinsic
undefined

x

Type: intrinsic
undefined

y

Type: intrinsic
undefined