-
controls
The control is displayed. -
autoplay
Open camera automatically -
facing
This is the camera face when opening the camera automatically.
Specify "front" for the front camera and "back" for the back camera.
The default is "back". -
width
The width of the camera resolution. -
height
The height of the camera resolution. -
dat-gui
The GUI option menu is displayed.
-
state: string
Returns the camera status.open The camera is open. loading The camera is preparing to open. close The camera is closed. -
opened: boolean
Returns true if the camera is open. -
paused: boolean
Returns true if the camera is paused. -
facingMode: string
Returns the open camera face.
back | The back camera is open. |
front | The front camera is open. |
undefined | The camera is closed. |
-
guiState: GuiState
If using dat-gui for the camera element, returns the GUI options that have been applied.
This object inherits the GuiState interface. -
resolution: { width: number, height: number }
Returns the camera resolution.
Open camera.
camera.open(facingMode: 'front'|'back' = 'back', width?: number, height?: number): Promise<void>
-
facingMode: string
Camera face.back Back camera. front Front camera. -
width: number|undefined
Width of resolution. The default is the initial value of the terminal. -
height: number|undefined
Height of resolution. The default is the initial value of the terminal.
Return promise.
Use the "autoplay" attribute on the Camera element and wait for it to be ready to open automatically.
camera.waitOpen(): Promise<void>
Return promise.
Close camera.
camera.close(): void
Pause the camera.
camera.pause(): void
Resume the camera from pause.
camera.play(): void
Returns the current frame image in data URL.
camera.capture(option?: {
/**
* Resize width (px). The default is no resizing (undefined).
* @type {number}
*/
width?: number,
/**
* Resize height (px). The default is no resizing (undefined).
* @type {number}
*/
height?: number,
/**
* This is the position to crop. The default is no crop (undefined).
* @type {{x: number, y: number, width: number, height: number}}
*/
extract?: {x: number, y: number, width: number, height: number},
/**
* Fit mode.
* @type {number}
*/
fit?: 'cover'|'contain'|'fill',
/**
* MIME type of the captured image.
* @type {number}
*/
format?: 'image/webp'|'image/png'|'image/jpeg'
}): string
-
width: number|undefined
Resize width (px). The default is no resizing (undefined). -
height: number|undefined
Specify the height when resizing the captured image. -
extract: {x: number, y: number, width: number, height: number}
This is the position to crop. The default is no crop (undefined). -
fit: 'cover'|'contain'|'fill'|undefined
How the image should be resized to fit both provided dimensions, one of cover, contain, fill. (optional, default 'fill')cover The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. The object will be clipped to fit. contain The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box. fill This is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit. -
format: 'image/webp'|'image/png'|'image/jpeg'|undefined
Capture image format.The default is "image/png".image/webp WebP image. image/png PNG image. image/jpeg JPEG image.
Returns the captured image as a string in data URL.
Returns the camera permissions.
camera.getPermission(): Promise<string|undefined>
Returns a promise that accepts a string with permission status.
granted | Caller will be able to successfuly access the feature without having the user agent asking the user’s permission. |
denied | Caller will not be able to access the feature. |
prompt | User agent will be asking the user’s permission if the caller tries to access the feature. The user might grant, deny or dismiss the request. |
undefined | Returns undefined when Permissions.query API is not supported. |
Revoke camera access settings.
camera.revokePermission(): Promise<void>
Return promise.
Add camera event listener.
camera.on(
type: string,
listener: () => void,
option: { once: boolean } = { once: false }
): Camera
-
type: string
event name. -
listener: (event?: Event) => void
Event listener callback function. -
option: { once: boolean } = { once: false } Event option. The following values can be set.
once If true, the listener would be automatically removed when invoked.The default is false.
Returns the camera element.
Remove event listener.
camera.off(
type: string,
listener: (event?: Event) => void
): Camera
Returns the camera element.
Fired when the camera opens.
camera.on('opened', event => {});
Fired when the camera plays from pause.
camera.on('played', event => {})
Fired when the camera pauses.
camera.on('paused', event => {});
Fired when you take a picture.
This is used to attach a control attribute to the camera element and receive shooting data when the shooting button is pressed.
camera.on('captured', event => {
console.log(event.detail.capture);// data:image/png;base64,iVB...
});
Interface for constraint objects used when opening a camera
-
video: Object
-
facingMode: string
Camera face.user Use front camera. environment Use the back camera. -
width: number|undefined
Camera resolution width. -
height: number|undefined
Camera resolution height.
-
-
audio: boolean
Use audio if true.
Interface for GUI option objects of camera elements.
-
resolution: string
Returns the width and height of the resolution, separated by commas. -
facingMode: string Camera face.
back Back camera. front Front camera. -
format: string
Format of photos to take.image/webp WebP image. image/png PNG image. image/jpeg JPEG image. -
resize: boolean
Returns true to resize the photo taken. -
width: number
The height to resize the picture taken. -
height: number
The width to resize the picture taken. -
fit: string
It is a fitting method when resizing the taken picture.cover The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. The object will be clipped to fit. contain The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box. fill This is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit.