[英]How to capture screenshot of parts of the client “desktop” using HTML/JavaScript ?
我知道如何捕获网页,但我问如何在桌面上捕获桌面或其他应用程序? 如果有任何方式突出显示部分屏幕。 就像html2canvas对网页的作用一样,我们可以使用HTML / JS中的浏览器应用程序为桌面应用程序做些什么吗?
对的,这是可能的!
但据我所知,只有Firefox和Chrome(我使用的是Chrome)。 感谢Screen Capturing和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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.