0

I'm trying to create a WriteableBitmap from an Image on my hard drive using WriteableBitmapEx. I copied the code from the official page after adding the nuget package:

WriteableBitmap writeableBmp = new WriteableBitmap(0, 0).FromResource("Data/flower2.png");

but I get the error

'System.Windows.Media.Imaging.WriteableBitmap' does not contain a constructor that takes 2 arguments

I have added the PresentationCore.dll as I was told here WriteableBitmapEx in console application? and also a using statement for System.Windows.Media.Imaging.

Community
  • 1
  • 1
Thomas
  • 4,030
  • 4
  • 40
  • 79
  • 1
    The answer to this is exactly what the compiler says. WriteableBitmap does not have a constructor that takes 2 arguments. http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.writeablebitmap(v=vs.100).aspx – alexander.biskop Mar 08 '13 at 16:24
  • Well I thought that's what the WriteableBitmapEx framework add? This code does work fine in my WinRT App. – Thomas Mar 08 '13 at 16:30

1 Answers1

5

The WriteableBitmapEx library provides a generic factory method for constructing writeable bitmaps, namely BitmapFactory.New. Use this portable method instead to generate your dummy writeable bitmap:

WriteableBitmap writeableBmp = BitmapFactory.New(0, 0).FromResource("Data/flower2.png");

The BitmapFactory class is in the System.Windows.Media.Imaging namespace (unless you are using the WinRT version of WriteableBitmapEx, where it is in the Windows.UI.Xaml.Media.Imaging namespace).

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114