2

I read How to: Encode and Decode a TIFF Image and copied the code

// Open a Stream and decode a TIFF image
Stream imageStreamSource = new FileStream("tulipfarm.tif", FileMode.Open, 
FileAccess.Read, FileShare.Read);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, 
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];

// Draw the Image
Image myImage = new Image();
myImage.Source = bitmapSource;
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(20);

into a console app in Visual Studio 2017. I added a reference to PresentationCore per https://stackoverflow.com/a/50192029/9044571 and that allowed me to add

using System.Windows.Media.Imaging;

But now I am getting an error (Error CS0144 Cannot create an instance of the abstract class or interface 'Image') associated with the line

Image myImage = new Image();

How might I fix this? Could the problem be that I am doing this from a console app?

1 Answers1

0

The reason why is, you are actually targeting the System.Drawing.Image class which is abstract

Fix is to either to :-

  1. Remove the wrong Namespace

  2. Using an Namespace alias

Namespace Aliases

The using Directive can also be used to create an alias for a namespace. For example, if you are using a previously written namespace that contains nested namespaces, you might want to declare an alias to provide a shorthand way of referencing one in particular, as in the following example:

using Co = Company.Proj.Nested;  // define an alias to represent a namespace
  1. Explicitly target the correct one

    var myImage = new System.Windows.Media.Imaging.Image();

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
  • Thanks. var myImage = new System.Windows.Media.Imaging.Image(); resulted in Error CS0234 The type or namespace name 'Image' does not exist in the namespace 'System.Windows.Media.Imaging' (are you missing an assembly reference?) – Steve Boege Apr 10 '19 at 04:36