ImageCapture.takePhoto() - Web APIs 编辑

The takePhoto() method of the ImageCapture interface takes a single exposure using the video capture device sourcing a MediaStreamTrack and returns a Promise that resolves with a Blob containing the data.

Syntax

const blobPromise = imageCaptureObj.takePhoto([photoSettings])

Parameters

photoSettings Optional
An object that sets options for the photo to be taken. The available options are:
  • fillLightMode:  The flash setting of the capture device, one of "auto", "off", or "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.

Return value

A Promise that resolves with a Blob.

Example

This example is extracted from this Simple Image Capture demo. It shows how to use the Promise returned by takePhoto() to copy the returned Blob to an <img> element. For simplicy it does not show how to instantiate the ImageCapture object.

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);
  });
}

Specifications

SpecificationStatusComment
MediaStream Image Capture
The definition of 'takePhoto()' in that specification.
Working DraftInitial definition.

Browser Compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:85 次

字数:3916

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文