Crea schermate di immagini perfette di siti Web o converti HTML direttamente in immagini utilizzando le seguenti funzionalità di API ASP.NET di GrabzIt. Tuttavia, prima di iniziare, ricordare che dopo aver chiamato il URLToImage, HTMLToImage or FileToImage metodi il Save or SaveTo Il metodo deve essere chiamato per acquisire lo screenshot.
È necessario un solo parametro per acquisire uno screenshot di una pagina Web o converti HTML into immagine come mostrato nell'esempio seguente.
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
L'API ASP.NET di GrabzIt può acquisire screenshot di immagini in diversi formati, tra cui JPG, PNG, WEBP, BMP (bit 8, bit 16, bit 24 o bit 32) e TIFF. Il formato predefinito per gli screenshot delle immagini è JPG. Tuttavia, la qualità di un'immagine JPG potrebbe non essere abbastanza buona per alcune applicazioni in queste circostanze, il formato PNG è raccomandato per gli screenshot delle immagini in quanto fornisce un buon equilibrio tra qualità e dimensione del file. L'esempio seguente mostra uno screenshot di immagine acquisito utilizzando il 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");
La dimensione del browser si riferisce alla dimensione della finestra del browser che verrà utilizzata durante l'acquisizione dello screenshot nella maggior parte dei casi, ciò non deve essere impostato poiché la dimensione predefinita del browser sarà sufficiente per tutte le attività. Per impostare la dimensione del browser, basta passare un valore a BrowserWidth
o BrowserHeight
proprietà del ImageOptions classe.
Cambiare le dimensioni di un'immagine è facile, farlo senza distorcere l'immagine è un po 'più difficile. Per semplificare l'intero processo, ti consigliamo di utilizzarlo semplice calcolatore delle dimensioni dell'immagine.
Se si desidera aumentare la larghezza e l'altezza dell'immagine ad una dimensione maggiore della larghezza e dell'altezza del browser, che per impostazione predefinita è 1366 per pixel 728, è necessario aumentare anche la larghezza e l'altezza del browser in modo che corrispondano.
È possibile passare un identificatore personalizzato a Immagine metodi come mostrato di seguito, questo valore viene quindi restituito al gestore GrabzIt ASP.NET. Ad esempio, questo identificatore personalizzato potrebbe essere un identificatore del database, consentendo di associare uno screenshot a un particolare record del database.
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");
GrabzIt ti permette di fare uno screenshot completo di un'intera pagina web per fare questo è necessario passare un -1 al BrowserHeight
proprietà del ImageOptions classe. Per assicurarsi che l'immagine corrisponda alle dimensioni del browser, passare un -1 al file OutputHeight
o OutputWidth
proprietà.
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");
Puoi anche restituire miniature che non sono ritagliate, ma fai attenzione perché puoi creare immagini di grandi dimensioni. Per fare questo passare un -1 al file OutputHeight
e / o OutputWidth
proprietà. Qualsiasi dimensione passata a -1 non verrà ritagliata.
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");
L'uso di questi valori speciali significa che è possibile creare uno screenshot che sia una versione in scala reale dell'intera pagina Web, se lo si desidera!
GrabzIt ti permette di fare uno screenshot di un elemento HTML, come a div
or span
tag e acquisisci tutto il suo contenuto. Per fare ciò, l'elemento HTML di cui vuoi fare uno screenshot deve essere specificato come Selettore CSS.
... <div id="features"> <img src="http://www.example.com/hot.jpg"/><h3>Heatwave Starting</h3> </div> ...
Nell'esempio seguente selezioneremo il div con l'id "caratteristiche" e lo emetteremo come immagine 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");
Il prossimo esempio prende un altro screenshot del div "features" ma questa volta genera un'immagine JPEG delle dimensioni esatte del 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");