-2

I am doing a photo editor, but I have a problem when creating a class, named MyImage, which I would like to put all the exif data. When I declare the inheritance in the code it falls.

   public class MyImage : Image 
   {
       private int iso;
       private float focalLength;
       private float shutterSpeed;
       private string flash;
       private float exposureTime;
       private string dataTime;
       private string cammeraModel;
       private string artist;
       private string copyright;
       private string geotag;
       private int rank;
       private string climate;
       private bool animal;
       private string path;

       public MyImage(string path)
       {
           Image file = Image.FromFile(path);
       }
  }

Which is the error?

  • what is exif data ? can you please be specific about the exact error, you are getting ? – Venkataraman R Sep 16 '19 at 04:22
  • exif data is the metadata of a image file. – Joaquín Barrientos Sep 16 '19 at 04:23
  • it seems it is a trouble with the inheritance of Image in this case, but I don't know why – Joaquín Barrientos Sep 16 '19 at 04:23
  • 4
    Don't derive from `Image`, it won't let you (as you saw), create a class that contains a `Image` and the exif rather than being a image itself. This is called "[Composition over Inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance)" – Scott Chamberlain Sep 16 '19 at 04:26
  • The error message is clear enough. `Image` isn't technically sealed, but as far as your code is concerned, it is. See marked duplicate for general advice on the situation. – Peter Duniho Sep 16 '19 at 04:32
  • You can use https://stackoverflow.com/questions/58649/how-to-get-the-exif-data-from-a-file-using-c-sharp. You can also create two classes : ExifData and ImageWithExifData that contains Image and ExifData. –  Sep 16 '19 at 05:10

1 Answers1

1

I'm assuming the Image you are using is the one in the System.Drawing namespace.

I took a look at the System.Drawing.Image class, and it looks like the constructor is internal. Thus, I don't believe it is possible for you to inherit from this class. Only classes in the same assembly as the Image class can do so.

Kei
  • 1,026
  • 8
  • 15