CropTarget

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Giao diện CropTarget của Screen Capture API cung cấp một phương thức tĩnh, fromElement(), trả về một thực thể CropTarget có thể dùng để cắt một track video được ghi lại theo vùng mà một phần tử chỉ định được hiển thị.

Static methods

fromElement() Experimental

Trả về một thực thể CropTarget có thể dùng để cắt một track video được ghi lại theo vùng mà một phần tử chỉ định được hiển thị.

Examples

js
// Options for getDisplayMedia()
const displayMediaOptions = {
  preferCurrentTab: true,
};

// Create crop target from DOM element
const demoElem = document.querySelector("#demo");
const cropTarget = await CropTarget.fromElement(demoElem);

// Capture video stream from user's webcam and isolate video track
const stream =
  await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
const [track] = stream.getVideoTracks();

// Crop video track
await track.cropTo(cropTarget);

// Broadcast cropped stream in <video> element
videoElem.srcObject = stream;

Xem Using the Element Capture and Region Capture APIs để biết mã ví dụ trong ngữ cảnh thực tế.

Specifications

Specification
Region Capture
# crop-target

Browser compatibility

See also