捕获和转换Web的工具

如何创建高清截图?

有时,您可能需要创建高清(HD)或视网膜屏幕截图。 高清晰度屏幕截图会变慢,并且随着尺寸的增大而变得越来越慢,因此建议不要创建太大的图像。 因此,您可能还需要指定一个延迟,以使屏幕快照有渲染的机会。

以下代码显示了如何通过将HD参数设置为true来制作每种语言的高清屏幕截图。 通过将图像的宽度和高度加倍,从而将标准屏幕截图的分辨率提高了四倍,从而创建了高分辨率的图像。 但是这会适得其反 将宽度和高度设置为-1以外的任何值 因为这将导致图像再次缩小!

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.HD = true;
options.OutputWidth = -1;
options.OutputHeight = -1;
grabzIt.URLToImage("https://www.bbc.co.uk", options);
grabzIt.SaveTo("images/result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.setHd(true);
options.setWidth(-1);
options.setHeight(-1);
grabzIt.URLToImage("https://www.bbc.co.uk", options);
grabzIt.SaveTo("images/result.jpg");
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.3.7/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertURL("https://www.bbc.co.uk", 
{"hd":true,"width":-1,"height":-1}).Create();
</script>
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
var options = {"hd":true,"width":"-1","height":"-1"};
client.url_to_image("https://www.bbc.co.uk", options);
client.save_to("images/result.jpg", function (error, id){
    if (error != null){
        throw error;
    }
});
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItImageOptions->new();
$options->hd(1);
$options->width(-1);
$options->height(-1);
$grabzIt->URLToImage("https://www.bbc.co.uk", $options);
$grabzIt->SaveTo("images/result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = new \GrabzIt\GrabzItImageOptions();
$options->setHD(true);
$options->setWidth(-1);
$options->setHeight(-1);
$grabzIt->URLToImage("https://www.bbc.co.uk", $options);
$grabzIt->SaveTo($filepath);
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzItImageOptions.GrabzItImageOptions()
options.hd  = True
options.width = -1
options.height = -1
grabzIt.URLToImage("https://www.bbc.co.uk", options)
grabzIt.SaveTo("images/result.jpg")
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzIt::ImageOptions.new()
options.hd = true
options.width = -1
options.height = -1
grabzItClient.url_to_image("https://www.bbc.co.uk", options)
grabzItClient.save_to("images/result.jpg")

左侧是标准屏幕截图的示例,右侧是由上面的代码生成的高清屏幕截图,两个屏幕截图的高度相同。


精确设置图像分辨率

还可以通过指定大于浏览器宽度的宽度来创建不同大小的高清屏幕截图。 然后GrabzIt缩放浏览器以停止拉伸图像。 但是以这种方式创建高清屏幕截图时进行的测量 不准确,这就是为什么在这种模式下,全长屏幕截图的大小或缩放比例不一定总是完美的原因。

如果您在使用此方法创建正确缩放的高清晰度图像时遇到问题,请尝试使用图像宽度和高度为原始浏览器尺寸的x2,x3或x4。

定位元素时,此模式也将无法正常工作。 如果要定位元素,建议您如上所述设置HD参数。