문제

텍스트와 이미지를 포함하여 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);
*/
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top