Anu*_*ran 3 html javascript screenshot html2canvas
我知道如何捕获网页,但我问如何捕获桌面或桌面中的其他应用程序?如果无论如何要突出显示屏幕的一部分。就像 html2canvas 为网页所做的那样,我们可以使用 HTML/JS 中的浏览器应用程序为桌面应用程序做一些事情吗?
对的,这是可能的!
但据我所知,仅适用于 Firefox 和 Chrome(我使用的是 Chrome)。感谢屏幕捕获和 WebRTC。关于 WebRTC 的更多信息
我使用了一个名为RTCMultiConnection的库,它非常易于使用,但您也应该能够在不使用任何库的情况下做到这一点。
在这里,只是给你一个起点:
// 1. Create the connection Objekt
var connection = new RTCMultiConnection();
// 2. Activate screen, which is the whole monitor, not only the browser window!
connection.session = {
screen: true,
data: false,
oneway: true
};
// 3. Create the callback for the stream
connection.onstream = function(event) {
// Make something with the event
// event.stream contains the stream, event.mediaElement the media
// I used event.mediaElement as parameter to draw the frage into an canvas; via context2d.drawImage(event.mediaElement, ...)
// Then I create an base64 String via canvas.toDataURL("image/png") and
// Don't forget to stop the stream if you just want to have one single image
};
// 4. Start Desktop Sharing
connection.open({
// you could register a onMediaCaptured callback here
});
Run Code Online (Sandbox Code Playgroud)