HTML 페이지를 .NET를 사용하여 이미지로 전환하는 무료 방법이 있습니까?
-
02-07-2019 - |
문제
텍스트와 이미지를 포함하여 HTML을 가져 와서 모든 것을 포함하는 하나의 이미지로 바꾸고 싶습니다. 자유로운 방법이 있습니까?
이것은 .NET 3.5를 사용하고 있습니다.
또한보십시오:
다른 팁
다음은 몇 주 전에 내 블로그에 게시 한 코드가 다음과 같습니다.
C#: 웹 페이지 썸네일 스크린 샷 이미지를 생성합니다
아래에 코드도 게시하겠습니다.
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;
}
여기에 몇 가지 예제가 있습니다.
// 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);
*/
제휴하지 않습니다 StackOverflow