How to Save Image from WebBrowser Control
-
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?
-
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?
Yes, find out what type parameter
DrawToDC
expects. It should be in the docs for IHTMLElementRender::DrawToDC.