Crie capturas de tela perfeitas de sites ou converta HTML diretamente em imagens usando os seguintes recursos de API ASP.NET do GrabzIt. No entanto, antes de começar, lembre-se de que depois de ligar para o URLToImage, HTMLToImage or FileToImage métodos os Save or SaveTo O método deve ser chamado para fazer a captura de tela.
Apenas um parâmetro é necessário para tirar uma captura de tela de uma página da web ou converter HTML intoa imagem como mostrado no exemplo a seguir.
grabzIt.URLToImage("https://www.tesla.com"); //Then call the Save or SaveTo method
grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>"); //Then call the Save or SaveTo method
grabzIt.FileToImage("example.html"); //Then call the Save or SaveTo method
A API ASP.NET da GrabzIt pode capturar capturas de tela de imagem em vários formatos, incluindo JPG, PNG, WEBP, BMP (bits 8, bits 16, bits 24 ou bits 32) e TIFF. O formato padrão para capturas de tela de imagens é JPG. No entanto, a qualidade de uma imagem JPG pode não ser boa o suficiente para alguns aplicativos nessas circunstâncias. O formato PNG é recomendado para capturas de tela de imagem, pois oferece um bom equilíbrio entre qualidade e tamanho do arquivo. O exemplo abaixo mostra uma captura de tela da imagem sendo usada no formato PNG.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.Format = ImageFormat.png; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.Format = ImageFormat.png; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.Format = ImageFormat.png; grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.png");
O tamanho do navegador se refere ao tamanho da janela do navegador que será usada ao capturar a captura de tela na maioria dos casos, isso não precisa ser definido, pois o tamanho padrão do navegador será suficiente para quase todas as tarefas. Para definir o tamanho do navegador, basta passar um valor para o BrowserWidth
e BrowserHeight
propriedades do ImageOptions classe.
É fácil alterar o tamanho de uma imagem, sem distorcer a imagem, é um pouco mais difícil. Para simplificar todo o processo, recomendamos que você use este calculadora de dimensão de imagem simples.
Se você deseja aumentar a largura e a altura da imagem para um tamanho maior que a largura e a altura do navegador, que por padrão é 1366 por pixels 728, a largura e a altura do navegador também devem ser aumentadas para corresponder.
Você pode passar um identificador personalizado para o imagem Como mostrado abaixo, esse valor é retornado ao seu manipulador GrabzIt ASP.NET. Por exemplo, esse identificador personalizado pode ser um identificador de banco de dados, permitindo que uma captura de tela seja associada a um registro específico do banco de dados.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.CustomId = "123456"; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.CustomId = "123456"; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.CustomId = "123456"; grabzIt.FileToImage("example.html", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
O GrabzIt permite que você tire uma captura de tela completa de uma página da web inteira para fazer isso. Você precisa passar um -1 para o BrowserHeight
propriedade do ImageOptions classe. Para garantir que a imagem corresponda ao tamanho do navegador, passe -1 para o OutputHeight
e OutputWidth
propriedades.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.BrowserHeight = -1; options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("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.BrowserHeight = -1; options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("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.BrowserHeight = -1; options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
Você também pode retornar miniaturas que não são cortadas, mas cuidado, isso pode criar imagens grandes. Para fazer isso, passe um -1 para o OutputHeight
e / ou OutputWidth
propriedades. Qualquer dimensão que for aprovada em um -1 não será cortada.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); ImageOptions options = new ImageOptions(); options.OutputWidth = -1; options.OutputHeight = -1; grabzIt.URLToImage("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("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.OutputWidth = -1; options.OutputHeight = -1; grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("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.OutputWidth = -1; options.OutputHeight = -1; grabzIt.FileToImage("example.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
O uso desses valores especiais significa que você pode criar uma captura de tela que seja uma versão em escala completa de toda a página da web, se desejar!
O GrabzIt permite tirar uma captura de tela de um elemento HTML, como um div
or span
tag e capturar todo o seu conteúdo. Para fazer isso, o elemento HTML do qual deseja fazer a captura de tela deve ser especificado como um Seletor CSS.
... <div id="features"> <img src="http://www.example.com/hot.jpg"/><h3>Heatwave Starting</h3> </div> ...
Para o exemplo abaixo, selecionaremos a div com o ID "features" e a produziremos como uma imagem JPEG 250 x 250px.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The 250 parameters indicates that image should be sized to 250 x 250 px ImageOptions options = new ImageOptions(); options.OutputWidth = 250; options.OutputHeight = 250; options.Format = ImageFormat.jpg; options.TargetElement = "#features"; grabzIt.URLToImage("http://www.bbc.co.uk/news", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");
O próximo exemplo tira outra captura de tela da div "features", mas desta vez gera uma imagem JPEG com o tamanho exato da div.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The -1 indicates that image should not be cropped ImageOptions options = new ImageOptions(); options.OutputWidth = -1; options.OutputHeight = -1; options.BrowserHeight = -1; options.Format = ImageFormat.jpg; options.TargetElement = "#features"; grabzIt.URLToImage("http://www.bbc.co.uk/news", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.jpg");