Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5958153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:30:09+00:00 2026-05-22T18:30:09+00:00

I am having a strange problem. I am trying to retrieve the images already

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:30:10+00:00Added an answer on May 22, 2026 at 6:30 pm

    The issue you are running into is that there are two different Clipboard classes, one for WinForms, and one for WPF. The WinForms one returns bitmaps that are suitable for use with WinForms, i.e. System.Drawing.Bitmap, which in the code you are using copies it to a System.Drawing.Image.

    Those types of bitmaps are not useful with WPF so the fact that you can’t convert what the WPF version of the Clipboard class is giving you to a type that is useful with WinForms is expected and not really your problem.

    Your problem is that for WPF you need a type of bitmap that you can use with WPF: a BitmapSource. That is something you can use with WPF controls like Image. So, back to your question:

    • if you are using WPF4 you can use Clipboard.GetImage which returns a BitmapSource, exactly what you need
    • if you are using anything else, you can use Thomas Levesque’s technique described here

    In summary:

    • For WinForms: WinForms clipboard => WinForms bitmaps
    • For WPF: WPF clipboard => WPF bitmaps
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a strange problem which I don't understand. I have the following
I am having a strange problem, maybe you can help: I'm trying to convert
I'm having a strange problem, that I've been trying to solve for too long.
I am having a really strange problem implementing Java REST service. I am trying
I'm having a rather strange problem with MySQL. Trying to create a procedure to
This is a strange problem that I am having with WCF trying to send
I'm having an interesting but difficult problem with my JavaScript code. Basically, I'm trying
I'm having a strange problem where a user can enter the following text Test
I've been having this strange problem with apply lately. Consider the following example: set.seed(42)
I'm having a strange problem when trying to run a maven build that uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.