Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to Save Image from WebBrowser Control

How to Save Image from WebBrowser Control

Scheduled Pinned Locked Moved Managed C++/CLI
graphicshelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    voo doo12
    wrote on last edited by
    #1

    Hi everybody. I'm tring to save image form webBrowser control. and i have the following code

    mshtml::HTMLDocument^ document = dynamic_castmshtml::HTMLDocument^(this->webBrowser1->Document->DomDocument);

    mshtml::IHTMLElementCollection^ collImages = document->getElementsByTagName(L"img");

    for(int i = 0; i < collImages->length; ++i)
    {
    mshtml::IHTMLImgElement^ img = safe_castmshtml::IHTMLImgElement^(collImages->item(nullptr, i));

    mshtml::IHTMLElementRender^ render = dynamic\_cast<mshtml::IHTMLElementRender^>(img);
    
    Bitmap^ bmp = gcnew Bitmap(img->width, img->height); 
    
    Graphics^ g = Graphics::FromImage(bmp);
    
    IntPtr hdc = g->GetHdc();    
    
    render->DrawToDC(hdc);  //Here is the Error 
    
    g->ReleaseHdc(hdc);
    
    delete g; 
    g = nullptr;
    
    bmp->Save(L"C:\\\\Test\\\\SaveImage.Jpg", System::Drawing::Imaging::ImageFormat::Jpeg);	
    

    }

    I get the following error message Error C2664: 'mshtml::IHTMLElementRender::DrawToDC' : cannot convert parameter 1 from 'System::IntPtr' to 'mshtml::_RemotableHandle %' is there any one who knows how to fix this?

    Richard Andrew x64R 1 Reply Last reply
    0
    • V voo doo12

      Hi everybody. I'm tring to save image form webBrowser control. and i have the following code

      mshtml::HTMLDocument^ document = dynamic_castmshtml::HTMLDocument^(this->webBrowser1->Document->DomDocument);

      mshtml::IHTMLElementCollection^ collImages = document->getElementsByTagName(L"img");

      for(int i = 0; i < collImages->length; ++i)
      {
      mshtml::IHTMLImgElement^ img = safe_castmshtml::IHTMLImgElement^(collImages->item(nullptr, i));

      mshtml::IHTMLElementRender^ render = dynamic\_cast<mshtml::IHTMLElementRender^>(img);
      
      Bitmap^ bmp = gcnew Bitmap(img->width, img->height); 
      
      Graphics^ g = Graphics::FromImage(bmp);
      
      IntPtr hdc = g->GetHdc();    
      
      render->DrawToDC(hdc);  //Here is the Error 
      
      g->ReleaseHdc(hdc);
      
      delete g; 
      g = nullptr;
      
      bmp->Save(L"C:\\\\Test\\\\SaveImage.Jpg", System::Drawing::Imaging::ImageFormat::Jpeg);	
      

      }

      I get the following error message Error C2664: 'mshtml::IHTMLElementRender::DrawToDC' : cannot convert parameter 1 from 'System::IntPtr' to 'mshtml::_RemotableHandle %' is there any one who knows how to fix this?

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Yes, find out what type parameter DrawToDC expects. It should be in the docs for IHTMLElementRender::DrawToDC.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups