files/en-us/web/api/imagecapture/takephoto/index.md
{{APIRef("Image Capture API")}}
The takePhoto() method of the
{{domxref("ImageCapture")}} interface takes a single exposure using the video capture
device sourcing a {{domxref("MediaStreamTrack")}} and returns a {{jsxref("Promise")}}
that resolves with a {{domxref("Blob")}} containing the data.
takePhoto()
takePhoto(photoSettings)
photoSettings {{optional_inline}}
fillLightMode
"auto", "off", or "flash".imageHeight
imageWidth
redEyeReduction
A {{jsxref("Promise")}} that resolves with a {{domxref("Blob")}}.
InvalidStateError {{domxref("DOMException")}}
readyState property of the MediaStreamTrack passing in the constructor is not live.UnknownError {{domxref("DOMException")}}
This example is extracted from this Simple Image Capture demo. It shows how to use the {{jsxref("Promise")}} returned by
takePhoto() to copy the returned {{domxref("Blob")}} to an
{{htmlelement("img")}} element. For simplicity it does not show how to instantiate the
{{domxref("ImageCapture")}} object.
let takePhotoButton = document.querySelector("button#takePhoto");
let canvas = document.querySelector("canvas");
takePhotoButton.onclick = takePhoto;
function takePhoto() {
imageCapture
.takePhoto()
.then((blob) => {
console.log("Took photo:", blob);
img.classList.remove("hidden");
img.src = URL.createObjectURL(blob);
})
.catch((error) => {
console.error("takePhoto() error: ", error);
});
}
{{Specifications}}
{{Compat}}