简体   繁体   English

页面一部分的 html2canvas 屏幕截图

[英]html2canvas screen capture for a portion of a page

I tried using html2canvas to generate a screen captures for a portion of the screen but It generates am image of the entire document.我尝试使用 html2canvas 为屏幕的一部分生成屏幕截图,但它会生成整个文档的图像。

Am I doing something wrong here ?我在这里做错了吗? ("graph" is a div id) (“图形”是一个 div id)

$("#graph").html2canvas();

Also,how do I save the resulting image to another location other than the specified element ?另外,如何将生成的图像保存到指定元素以外的其他位置?

Can you clarify what you mean by saving the image to another location?您能否通过将图像保存到另一个位置来阐明您的意思? If I'm understanding what you're asking, assuming you are using the " jquery.plugin.html2canvas.js ", you need to edit the "$canvas.css" line in that file, to specify where you want to append your canvas object.如果我理解您的要求,假设您使用的是“ jquery.plugin.html2canvas.js ”,则您需要编辑该文件中的“$canvas.css”行,以指定要将您的画布对象。

One option you may consider is to keep it appending to the body, but set the css to "display: none" so that the object doesn't keep showing up.您可能会考虑的一种选择是将其附加到正文中,但将 css 设置为“display: none”,这样对象就不会一直显示。 Then, after the css properties you can put in your own function to manipulate the canvas object.然后,在 css 属性之后,您可以放入自己的函数来操作画布对象。

$canvas.css({width: '500px', height: '500px', display:'none'}).appendTo(document.body);
$canvas.attr('id', 'canvasObj');
manipulateCanvasFunction(document.getElementById('canvasObj'));

This sends the complete canvas object to your "manipulateCanvasFunction," and you can do whatever you want with the canvas object.这会将完整的画布对象发送到您的“manipulateCanvasFunction”,您可以对画布对象执行任何您想要的操作。

You might check out this question thread for some other ideas.您可以查看问题线程以了解其他一些想法。

Edit: Removing incorrect information编辑:删除不正确的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM