0

I am trying to use an object of type System.Drawing.Bitmap in a standard WPF application (VB or C#). But I can't seem to get a reference to it Any declaration such as

Dim b as System.Drawing.Bitmap

will give me error. This is possible in a Windows forms application but not in WPF. Am I missing something? I am simply trying this solution here.

Thank you

Luis
  • 26
  • 9
  • what error do you get? – Francesco B. May 11 '18 at 20:39
  • 1
    `System.Drawing.Bitmap` is a GDI+ object, not WPF. You can reference `System.Drawing.dll`, but you won't be able to convert it to a WPF `ImageSource` (not directly anyway) so if this is useful or not depends on what you intend to do with it. – Ron Beyer May 11 '18 at 20:40
  • References -> right-click-> add System.Drawing. And them Imports System.Drawing. I tested it and it works in a WPF VB.NET project @Luis – Francesco B. May 11 '18 at 20:41
  • Also, I would look into what @RonBeyer says. – Francesco B. May 11 '18 at 20:42
  • Ah. Thanks Francesco. That worked. – Luis May 11 '18 at 21:20
  • Use `BitmapImage`, importing `System.Drawing` shouldnt be what you need in a WPF application, rethink your approach. See here https://learn.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-use-a-bitmapimage – Trevor May 11 '18 at 21:26
  • While you typically don't use System.Drawing.Bitmap in a WPF app, getting a bitmap from the clipboard seems to be an exception. And saying *"you won't be able to convert it to a WPF ImageSource"* is certainly wrong. There are multipe ways to do the conversion, e.g. [this](https://stackoverflow.com/q/30727343/1136211). An alternative without System.Drawing.Bitmap is described here: https://www.thomaslevesque.com/2009/02/05/wpf-paste-an-image-from-the-clipboard/ – Clemens May 11 '18 at 22:07
  • Thank you for your help. I had problems getting certain bitmaps from clipboard. I am 90% sure now that this is a bug in WPF, but not in WinForms, reason why I was seeking a solution using WinForms API. This workaround worked, but I am hoping is temporary until MS resolves the importing issues. – Luis May 13 '18 at 08:59

0 Answers0