我想知道是否有可能从基于JavaScript的web应用程序中捕获客户端桌面的屏幕截图。我想为用户提供一个应用程序中的按钮,他们可以用来截取他们的桌面屏幕(不是页面,或页面中的元素,实际的OS桌面屏幕)的屏幕截图。
主流浏览器(Chrome和Firefox)允许这种操作吗?我知道可能会有安全问题,但我可以请求用户的许可来拥有这种访问权限吗?有没有什么库、工具或文档可以帮助我呢?或者这是不可行的?
我在这个问题上做了一些研究,但只找到了在浏览器中截取内容的方法。
发布于 2017-10-18 19:41:56
看起来这个会对你有帮助:How to capture screenshot of parts of the client "desktop" using HTML/JavaScript ?
使用WebRTC和Screen Capturing,你可以截取桌面截图(火狐和Chrome都支持)。Javascript库RTCMultiConnection对于使用WebRTC非常有用,但也可以在不使用附加库的情况下使用它。
发布于 2017-10-18 20:06:25
是的,它允许这样做。我不知道这是不是一个开始的好方法,但是你可以研究一个开源的应用程序来做这项工作。
这里是铬遥控应用程序的源代码。您可以找到捕获屏幕的代码片段。如果你把工作做完了,我希望能听到你的消息。
铬遥控器应用link
发布于 2017-10-18 19:50:07
使用Canvas只能截取图片或视频帧作为截图。但是,如果您想要捕获web页面上的特定元素,可以尝试这个库:html2canvas
代码如下:
注意:在drawImage()函数中仔细调整尺寸
$(".drag").draggable();
$(".drag").droppable();
var takeScreenShot = function() {
html2canvas(document.getElementById("container"), {
onrendered: function (canvas) {
var tempcanvas=document.createElement('canvas');
tempcanvas.width=350;
tempcanvas.height=350;
var context=tempcanvas.getContext('2d');
context.drawImage(canvas,112,0,288,200,0,0,350,350);
var link=document.createElement("a");
link.href=tempcanvas.toDataURL('image/jpg'); //function blocks CORS
link.download = 'screenshot.jpg';
link.click();
}
});
}#container{
width:400px;
height:200px;
}
#rightcontainer{
width:300px;
height:200px;
background:gray;
color:#fff;
margin-left:110px;
padding:10px;
}
#leftmenu{
color:#fff;
background-color:green;
width:100px;
height:200px;
position:fixed;
left:0;
padding:10px;
}
button{
display:block;
height:20px;
margin-top:10px;
margin-bottom:10px;
}
.drag{
width:40px;
height:20px;
background-color:blue;
z-index:100000;
margin-top:10px;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<button onclick="takeScreenShot()">Snapshot</button>
<div id="container">
<div id="leftmenu">
Left Side
<div class="drag">
</div>
<div class="drag">
</div>
<div class="drag">
</div>
Drag----------->
&
Click Snapshot
</div>
<div id="rightcontainer">
Right Side
</div>
</div>
https://stackoverflow.com/questions/46809256
复制相似问题