ImageCapture:getPhotoSettings() 方法
ImageCapture 介面的 getPhotoSettings() 方法返回一個 Promise,該 Promise 解析為一個包含當前照片配置設定的物件。
語法
js
getPhotoSettings()
引數
無。
返回值
一個 Promise,解析為一個包含以下屬性的物件:
fillLightMode-
捕獲裝置的閃光燈設定,可以是
"auto"、"off"或"flash"之一。 imageHeight-
所需的影像高度(整數)。如果瀏覽器只支援離散高度,它將選擇最接近此設定的寬度值。
imageWidth-
所需的影像寬度(整數)。如果瀏覽器只支援離散寬度,它將選擇最接近此設定的寬度值。
redEyeReduction-
一個布林值,指示如果可用,是否應使用紅眼消除。
異常
InvalidStateErrorDOMException-
如果建構函式中傳入的
MediaStreamTrack的readyState屬性不是live,則丟擲此異常。 OperationErrorDOMException-
如果由於任何原因操作無法完成,則丟擲此異常。
示例
下面的示例摘自 Chrome 的 Image Capture / Photo Resolution 示例,它使用 getPhotoSettings() 的結果來修改輸入範圍的大小。此示例還展示瞭如何使用從裝置的 MediaStream 中檢索到的 MediaStreamTrack 來建立 ImageCapture 物件。
js
const input = document.querySelector('input[type="range"]');
let imageCapture;
navigator.mediaDevices
.getUserMedia({ video: true })
.then((mediaStream) => {
document.querySelector("video").srcObject = mediaStream;
const track = mediaStream.getVideoTracks()[0];
imageCapture = new ImageCapture(track);
return imageCapture.getPhotoCapabilities();
})
.then((photoCapabilities) => {
const settings = imageCapture.track.getSettings();
input.min = photoCapabilities.imageWidth.min;
input.max = photoCapabilities.imageWidth.max;
input.step = photoCapabilities.imageWidth.step;
return imageCapture.getPhotoSettings();
})
.then((photoSettings) => {
input.value = photoSettings.imageWidth;
})
.catch((error) => console.error("Argh!", error.name || error));
規範
| 規範 |
|---|
| MediaStream 影像捕獲 # dom-imagecapture-getphotosettings |
瀏覽器相容性
載入中…