Existe-t-il un moyen gratuit de transformer une page html en une image avec .net
-
02-07-2019 - |
Question
Je veux utiliser le langage HTML, y compris le texte et les images, et le transformer en une seule image contenant tout. Y a-t-il un moyen gratuit de le faire?
Ceci utilise .net 3.5.
Voir aussi:
captures d'écran Web générées par le serveur?
Quel est le meilleur moyen de créer une page Web miniature?
La solution
Vous pouvez consulter ce projet ou cette page .
L’espoir que cela aide.
Autres conseils
Voici un code que j'ai posté sur mon blog il y a quelques semaines et qui fait ceci:
C #: Générer WebPage Vignette Image de la capture d'écran
Je posterai également le code correspondant ci-dessous:
public Bitmap GenerateScreenshot(string url)
{
// This method gets a screenshot of the webpage
// rendered at its full size (height and width)
return GenerateScreenshot(url, -1, -1);
}
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
Voici quelques exemples d'utilisation:
// Generate thumbnail of a webpage at 1024x768 resolution
Bitmap thumbnail = GenerateScreenshot("http://pietschsoft.com", 1024, 768);
// Generate thumbnail of a webpage at the webpage's full size (height and width)
thumbnail = GenerateScreenshot("http://pietschsoft.com");
// Display Thumbnail in PictureBox control
pictureBox1.Image = thumbnail;
/*
// Save Thumbnail to a File
thumbnail.Save("thumbnail.png", System.Drawing.Imaging.ImageFormat.Png);
*/
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow