问题描述
是否有免费工具可以读取给定网页并截取它的屏幕截图?
Is there a free tool that can read given webpage and take a screenshot of it?
推荐答案
建立两个上面的答案:
用Java渲染HTML然后保存到图像 - 存在一些基于Java的HTML渲染,它们都有不同的缺点。最常见的是。这非常简单,只能呈现相当基本的HTML。我所知道的最有趣的是。这可以渲染相当复杂的XHTML,但您必须先转换HTML才能使用它(可能能够在这里帮忙)。使用Swing组件并创建图像非常简单,只需传递一个 s 对象并将其传递给Swing组件方法。然后使用将其删除。
这样做的一个很大的好处就是渲染器会无头。缺点是它不是一个完美的渲染,它将缺少任何插件。
Rendering the HTML in Java then saving to an image - A few Java based HTML renders exist, all with different sets of drawbacks. The most common is the one built in. This is quite simple and can only render fairly basic HTML. The most intresting I know of is The Flying Saucer Project. This can render fairly complex XHTML but you will have to convert HTML before you can use it (JTindy may be able to help here). Taking a Swing component and creating a image is fairly simple, you just pass an BufferedImage
s graphics object and pass it to the Swing components paint method. Then splat that out with ImageIO.
A big advantage to this would be that the renderer would be headless. The disadvantage is that it would not be a perfect rendering and it would lack any plugins.
第二个选项要求你启动一个Web浏览器,找出它的位置和然后拍一个屏幕截图。您也可以选择删除所有Firefox / IE / Opera / etc菜单,只留下图片。要获得Web浏览器的尺寸,最简单的选择是全屏启动。另一种选择是使用像JDIC这样的东西组件将其作为Java应用程序的一部分包含在内。然后它可以指定HTML在屏幕上呈现的位置,然后只需使用创建该区域的屏幕截图。
这样做的最大优点是它可以提供完美的渲染(对于给定的浏览器)。两个缺点是它需要本机代码(或至少使用本机组件)并且它不能无头¹。
The second option requires you to start a web browser, work out where it is and then take a screen shot. Optionally you may also wish to strip out all the Firefox/IE/Opera/etc menus leaving you with just image. To get the dimensions of the web browser the simplest option would be to start it full screen. The other option would be to use something like JDICs browser component to include it as part of the Java application. It would then be able to specify where the HTML is being rendered on screen and then simply use Robot to create a screen shot of that area.
The big advantage to this is that it will give a perfect rendering (for a given browser). The two disadvantages is that it would require native code (or at least using a native component) and it could not be headless¹.
1)您可以使用虚拟帧缓冲区。但那是在Java之外。
1) You could use a virtual frame buffer. But that is outside Java.
这篇关于用Java截取网页截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!