takePhoto()
方法在
ImageCapture
interface takes a single exposure using the video capture device sourcing a
MediaStreamTrack
并返回
Promise
that resolves with a
Blob
containing the data.
const blobPromise = imageCaptureObj.takePhoto([photoSettings])
photoSettings
可选
fillLightMode
: The flash setting of the capture device, one of
"auto"
,
"off"
,或
"flash"
.
imageHeight
: The desired image height as an integer. The user agent selects the closest height value to this setting if it only supports discrete heights.
imageWidth
: The desired image width as an integer. The user agent selects the closest width value to this setting if it only supports discrete widths.
redEyeReduction
: A boolean indicating whether the red-eye reduction should be used if it is available.
A
Promise
that resolves with a
Blob
.
This example is extracted from this
Simple Image Capture demo
. It shows how to use the
Promise
返回通过
takePhoto()
to copy the returned
Blob
to an
<img>
element. For simplicy it does not show how to instantiate the
ImageCapture
对象。
var takePhotoButton = document.querySelector('button#takePhoto');
var canvas = document.querySelector('canvas');
takePhotoButton.onclick = takePhoto;
function takePhoto() {
imageCapture.takePhoto().then(function(blob) {
console.log('Took photo:', blob);
img.classList.remove('hidden');
img.src = URL.createObjectURL(blob);
}).catch(function(error) {
console.log('takePhoto() error: ', error);
});
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
MediaStream 图像捕获
The definition of 'takePhoto()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
takePhoto
|
Chrome
60
|
Edge ≤79 | Firefox ? | IE ? |
Opera
47
|
Safari ? |
WebView Android
60
|
Chrome Android
60
|
Firefox Android ? |
Opera Android
44
|
Safari iOS ? |
Samsung Internet Android
8.0
|
完整支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
ImageCapture
getPhotoCapabilities()
getPhotoSettings()
grabFrame()
takePhoto()