Wpf InteropBitmap for bitmap

I have a strange problem. I am trying to get images already loaded into a 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 a WPF application, gives an error on

using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().......

The error is as follows:

"Cannot pass an object of type 'System.Windows.Interop.InteropBitmap' to enter 'System.Drawing.Bitmap'."

How to solve this?

Please can you provide any recommendations.

Thanks in advance.

+3
source share
1 answer

, , , Clipboard, WinForms WPF. WinForms , WinForms, .. System.Drawing.Bitmap, , , System.Drawing.Image.

WPF, , , , WPF- Clipboard , WinForms, .

, WPF , WPF: a BitmapSource. , WPF, Image. , :

  • WPF4, Clipboard.GetImage, BitmapSource, ,
  • - , ,

:

  • WinForms: WinForms clipboard = > WinForms
  • WPF: WPF = > WPF
+4

All Articles