|
| 1 | +# @capacitor/camera |
| 2 | + |
| 3 | +The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @capacitor/camera |
| 9 | +npx cap sync |
| 10 | +``` |
| 11 | + |
| 12 | +## API |
| 13 | + |
| 14 | +<docgen-index> |
| 15 | + |
| 16 | +* [`getPhoto(...)`](#getphoto) |
| 17 | +* [`checkPermissions()`](#checkpermissions) |
| 18 | +* [`requestPermissions(...)`](#requestpermissions) |
| 19 | +* [Interfaces](#interfaces) |
| 20 | +* [Type Aliases](#type-aliases) |
| 21 | + |
| 22 | +</docgen-index> |
| 23 | + |
| 24 | +<docgen-api> |
| 25 | +<!--Update the source file JSDoc comments and rerun docgen to update the docs below--> |
| 26 | + |
| 27 | +### getPhoto(...) |
| 28 | + |
| 29 | +```typescript |
| 30 | +getPhoto(options: CameraOptions) => Promise<CameraPhoto> |
| 31 | +``` |
| 32 | + |
| 33 | +Prompt the user to pick a photo from an album, or take a new photo |
| 34 | +with the camera. |
| 35 | + |
| 36 | +| Param | Type | |
| 37 | +| ------------- | ------------------------------------------------------- | |
| 38 | +| **`options`** | <code><a href="#cameraoptions">CameraOptions</a></code> | |
| 39 | + |
| 40 | +**Returns:** <code>Promise<<a href="#cameraphoto">CameraPhoto</a>></code> |
| 41 | + |
| 42 | +**Since:** 1.0.0 |
| 43 | + |
| 44 | +-------------------- |
| 45 | + |
| 46 | + |
| 47 | +### checkPermissions() |
| 48 | + |
| 49 | +```typescript |
| 50 | +checkPermissions() => Promise<CameraPermissionStatus> |
| 51 | +``` |
| 52 | + |
| 53 | +Check camera and photo album permissions |
| 54 | + |
| 55 | +**Returns:** <code>Promise<<a href="#camerapermissionstatus">CameraPermissionStatus</a>></code> |
| 56 | + |
| 57 | +**Since:** 1.0.0 |
| 58 | + |
| 59 | +-------------------- |
| 60 | + |
| 61 | + |
| 62 | +### requestPermissions(...) |
| 63 | + |
| 64 | +```typescript |
| 65 | +requestPermissions(permissions?: CameraPluginPermissions | undefined) => Promise<CameraPermissionStatus> |
| 66 | +``` |
| 67 | + |
| 68 | +Request camera and photo album permissions |
| 69 | + |
| 70 | +| Param | Type | |
| 71 | +| ----------------- | --------------------------------------------------------------------------- | |
| 72 | +| **`permissions`** | <code><a href="#camerapluginpermissions">CameraPluginPermissions</a></code> | |
| 73 | + |
| 74 | +**Returns:** <code>Promise<<a href="#camerapermissionstatus">CameraPermissionStatus</a>></code> |
| 75 | + |
| 76 | +**Since:** 1.0.0 |
| 77 | + |
| 78 | +-------------------- |
| 79 | + |
| 80 | + |
| 81 | +### Interfaces |
| 82 | + |
| 83 | + |
| 84 | +#### CameraPhoto |
| 85 | + |
| 86 | +| Prop | Type | Description | Since | |
| 87 | +| ------------------ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | |
| 88 | +| **`base64String`** | <code>string</code> | The base64 encoded string representation of the image, if using <a href="#cameraresulttype">CameraResultType</a>.Base64. | 1.0.0 | |
| 89 | +| **`dataUrl`** | <code>string</code> | The url starting with 'data:image/jpeg;base64,' and the base64 encoded string representation of the image, if using <a href="#cameraresulttype">CameraResultType</a>.DataUrl. | 1.0.0 | |
| 90 | +| **`path`** | <code>string</code> | If using <a href="#cameraresulttype">CameraResultType</a>.Uri, the path will contain a full, platform-specific file URL that can be read later using the Filsystem API. | 1.0.0 | |
| 91 | +| **`webPath`** | <code>string</code> | webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering. | 1.0.0 | |
| 92 | +| **`exif`** | <code>any</code> | Exif data, if any, retrieved from the image | 1.0.0 | |
| 93 | +| **`format`** | <code>string</code> | The format of the image, ex: jpeg, png, gif. iOS and Android only support jpeg. Web supports jpeg and png. gif is only supported if using file input. | 1.0.0 | |
| 94 | + |
| 95 | + |
| 96 | +#### CameraOptions |
| 97 | + |
| 98 | +| Prop | Type | Description | Default | Since | |
| 99 | +| ------------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | ----- | |
| 100 | +| **`quality`** | <code>number</code> | The quality of image to return as JPEG, from 0-100 | | 1.0.0 | |
| 101 | +| **`allowEditing`** | <code>boolean</code> | Whether to allow the user to crop or make small edits (platform specific) | | 1.0.0 | |
| 102 | +| **`resultType`** | <code><a href="#cameraresulttype">CameraResultType</a></code> | How the data should be returned. Currently, only 'Base64', 'DataUrl' or 'Uri' is supported | | 1.0.0 | |
| 103 | +| **`saveToGallery`** | <code>boolean</code> | Whether to save the photo to the gallery. If the photo was picked from the gallery, it will only be saved if edited. | <code>: false</code> | 1.0.0 | |
| 104 | +| **`width`** | <code>number</code> | The width of the saved image | | 1.0.0 | |
| 105 | +| **`height`** | <code>number</code> | The height of the saved image | | 1.0.0 | |
| 106 | +| **`preserveAspectRatio`** | <code>boolean</code> | Whether to preserve the aspect ratio of the image. If this flag is true, the width and height will be used as max values and the aspect ratio will be preserved. This is only relevant when both a width and height are passed. When only width or height is provided the aspect ratio is always preserved (and this option is a no-op). A future major version will change this behavior to be default, and may also remove this option altogether. | <code>: false</code> | 1.0.0 | |
| 107 | +| **`correctOrientation`** | <code>boolean</code> | Whether to automatically rotate the image "up" to correct for orientation in portrait mode | <code>: true</code> | 1.0.0 | |
| 108 | +| **`source`** | <code><a href="#camerasource">CameraSource</a></code> | The source to get the photo from. By default this prompts the user to select either the photo album or take a photo. | <code>: CameraSource.prompt</code> | 1.0.0 | |
| 109 | +| **`direction`** | <code><a href="#cameradirection">CameraDirection</a></code> | iOS and Web only: The camera direction. | <code>: CameraDirection.rear</code> | 1.0.0 | |
| 110 | +| **`presentationStyle`** | <code>'fullscreen' \| 'popover'</code> | iOS only: The presentation style of the Camera. | <code>: 'fullscreen'</code> | 1.0.0 | |
| 111 | +| **`webUseInput`** | <code>boolean</code> | Web only: Whether to use the PWA Element experience or file input. The default is to use PWA Elements if installed and fall back to file input. To always use file input, set this to `true`. Learn more about PWA Elements: https://capacitorjs.com/docs/pwa-elements | | 1.0.0 | |
| 112 | +| **`promptLabelHeader`** | <code>string</code> | Text value to use when displaying the prompt. iOS only: The title of the action sheet. | <code>: 'Photo'</code> | 1.0.0 | |
| 113 | +| **`promptLabelCancel`** | <code>string</code> | Text value to use when displaying the prompt. iOS only: The label of the 'cancel' button. | <code>: 'Cancel'</code> | 1.0.0 | |
| 114 | +| **`promptLabelPhoto`** | <code>string</code> | Text value to use when displaying the prompt. The label of the button to select a saved image. | <code>: 'From Photos'</code> | 1.0.0 | |
| 115 | +| **`promptLabelPicture`** | <code>string</code> | Text value to use when displaying the prompt. The label of the button to open the camera. | <code>: 'Take Picture'</code> | 1.0.0 | |
| 116 | + |
| 117 | + |
| 118 | +#### CameraPermissionStatus |
| 119 | + |
| 120 | +| Prop | Type | |
| 121 | +| ------------ | ----------------------------------------------------------------------- | |
| 122 | +| **`camera`** | <code><a href="#camerapermissionstate">CameraPermissionState</a></code> | |
| 123 | +| **`photos`** | <code><a href="#camerapermissionstate">CameraPermissionState</a></code> | |
| 124 | + |
| 125 | + |
| 126 | +#### CameraPluginPermissions |
| 127 | + |
| 128 | +| Prop | Type | |
| 129 | +| ----------------- | ----------------------------------- | |
| 130 | +| **`permissions`** | <code>CameraPermissionType[]</code> | |
| 131 | + |
| 132 | + |
| 133 | +### Type Aliases |
| 134 | + |
| 135 | + |
| 136 | +#### CameraResultType |
| 137 | + |
| 138 | +<code>'uri' | 'base64' | 'dataUrl'</code> |
| 139 | + |
| 140 | + |
| 141 | +#### CameraSource |
| 142 | + |
| 143 | +<code>'prompt' | 'camera' | 'photos'</code> |
| 144 | + |
| 145 | + |
| 146 | +#### CameraDirection |
| 147 | + |
| 148 | +<code>'rear' | 'front'</code> |
| 149 | + |
| 150 | + |
| 151 | +#### CameraPermissionState |
| 152 | + |
| 153 | +<code><a href="#permissionstate">PermissionState</a> | 'limited'</code> |
| 154 | + |
| 155 | + |
| 156 | +#### PermissionState |
| 157 | + |
| 158 | +<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code> |
| 159 | + |
| 160 | + |
| 161 | +#### CameraPermissionType |
| 162 | + |
| 163 | +<code>'camera' | 'photos'</code> |
| 164 | + |
| 165 | +</docgen-api> |
0 commit comments