I am having a strange problem. I am trying to retrieve the images already loaded in webbrowser control. The following code works fine in a WinForms application:
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)__ie.NativeDocument.BODY).createControlRange();
foreach (IHTMLImgElement img in __ie.NativeDocument.Images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
var image = System.Drawing.Image.FromStream(stream);
}
}
But the same code if I use in WPF application gives error on
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().......
The error is as follows:
"Unable to cast object of type 'System.Windows.Interop.InteropBitmap' to type 'System.Drawing.Bitmap'."
How do I solve this?
Please can anyone provide any guidance.
Thank you in advance.