Provide state-of-the-art image capture, screen capture, video capture and audio capture software
Home     Download     Purchase     Support     Contact     View my shopping cart
You are here: ACASystems » ACA WebThumb ActiveX Control » FAQ » Convert HTML to image with Visual C++

How to convert HTML to image with Visual C++? - VC++ Sample Code

Are you looking for a solution to convert html to image in your Visual C++ application? ACA WebThumb ActiveX is one of the best choices you can save long HTML page to image as as JPG, GIF, PNG, BMP, TIFF, WMF and EMF format with a few function calls, you can get the image bytes in memory and image bitmap Handle also. Now, you can easily add "HTML to PNG", "HTML to JPG", "Web thumbnail maker" feature in your VC++ application.

Guidelines: Convert HTML to image with ASP

  1. Free download ACA WebThumb ActiveX, and then install it on your computer.
  2. You will find the Visual C++ sample project in the folder {install-folder}\sample\vc.
  3. You can open the project VC6.dsw(For VC++ 6.0) or VS2005.sln(For VS 2005 or VS S2008) to build it, and then launch it.

Free Trial ACA WebThumb ActiveX Now

Example code: Convert HTML to image with VC++

1. A simple VC++ code for converting HTML to image

//
// Function: Convert_HTML_To_Image()
//  This VC++ sample shows how to convert the HTML page to image, save as PNG format,
//  and then call WIN32API ShellExecute() to open the image by default image viewer
//
void Convert_HTML_To_Image()
{
  CoInitialize(NULL);   // Initializes the COM library on the current thread
    
  HRESULT hr;
  IThumbMaker * t_pWebThumbMaker = NULL;
  hr = CoCreateInstance(
    __uuidof(ThumbMaker), NULL, CLSCTX_INPROC_SERVER, 
    __uuidof(IThumbMaker), (void**)&t_pWebThumbMaker
    );
  if ( SUCCEEDED(hr)  )
  {
    t_pWebThumbMaker->SetURL("http://www.acasystems.com"); // Set URL
    if ( 0 == t_pWebThumbMaker->StartSnap() )
    {
      // Save as PNG image
      t_pWebThumbMaker->SaveImage( _T("c:/acasystems-snapshot.png") ); 
      // call WIN32API ShellExecute() to open the image by default image viewer.
      ShellExecute( NULL, _T("open"), _T("c:/acasystems-snapshot.png"), NULL, NULL, SW_SHOW);
    }
    t_pWebThumbMaker->Release();
  }
  CoUninitialize();
}

2. VC++ Sample: Convert HTML to image and get the image HBITMAP handle

//
// Function: Convert_HTML_To_HBITMAP()
//  This VC++ sample shows how to convert the HTML page to image, 
//  and then call GetBitmapHandle() to get the HBITMAP handle in memory.
//
void Convert_HTML_To_HBITMAP()
{
  HRESULT hr;
  IThumbMaker * t_pWebThumbMaker = NULL;
  
  CoInitialize(NULL);  // Initializes the COM library on the current thread

  hr = CoCreateInstance(
    __uuidof(ThumbMaker), NULL, CLSCTX_INPROC_SERVER, 
    __uuidof(IThumbMaker), (void**)&t_pWebThumbMaker
    );

  if ( SUCCEEDED(hr)  )
  {
    long t_lRet = 0;
    t_pWebThumbMaker->SetURL( _T("http://www.acasystems.com") );
    t_lRet = t_pWebThumbMaker->StartSnap();
    if ( 0 == t_lRet )
    {
      // Snap successful, call GetBitmapHandle() to get the HBITMAP handle 
      HBITMAP t_hBitmapHandle = (HBITMAP)t_pWebThumbMaker->GetBitmapHandle();
      if ( NULL != t_hBitmapHandle )
      {
        // TODO: Add your codes here ...
        // ...

        // Delete the bitmap handle
        DeleteObject(t_hBitmapHandle);
      }
    }
    t_pWebThumbMaker->Release();
  }
  CoUninitialize(); // Don't forget close the COM library on the current thread
}

Free Trial ACA WebThumb ActiveX Now

Other resource about Converting HTML to image with ASP:

  • FAQ: How to convert YouTube Flash video webpage to image?
  • FAQ: Which image format is best?
  • FAQ: What programming languages does ACA WebThumb ActiveX Control support?
  • ACA WebThumb ActiveX Interface Reference
  • C# Sample Code: How to take screenshot of web page in C#(C-sharp)?

  • Get discount alerts, new product information and technical articles:
    Name:
    Email:
    * Get 10% off your first order by joining our mailing list!
    * You may safely unsubscribe at any time!