Jerry,
You can't really derive from System.Drawing.Image. I was looking at the
class in reflector, and all the constructors are marked as internal (as is
the default one with no parameters), which means that you can't define an
implementation outside of System.Drawing.dll.
The reason why the call to FromFile works is that FromFile is returning
an instance of a derived class. You can access abstract types in your code.
The whole point of abstract classes is that they help provide some base
implementation details (otherwise, it would be the same as an interface if
it only defined methods which needed to be overridden) so that you have a
contract (the class definition of the abstract type) which you can access,
regardless of the derived type.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Jerry J" <Je****@discussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
>I define a class like this:
public class Image : System.Drawing.Image
{
public Image() {}
}
The error: 'System.Drawing.Image.Image()' is inaccessible due to its
protection level occurs if I do this:
Image myImage = new Image();
The other thing I don't understand is why I am able to do the following
without getting an error. Since it is abstract, shouldn't this not be
allowed
because it instantiates an image object?
System.Drawing.Image Jpg = System.Drawing.Image.FromFile(PathToFile);
--
Jerry J
"Nicholas Paldino [.NET/C# MVP]" wrote:
>Jerry,
You can inherit from it. However, we can't see how you have tried to
implement it, so we can't say what the problem might be. Can you post
the
code of your implementation?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jerry J" <Je****@discussions.microsoft.comwrote in message
news:13**********************************@microso ft.com...
>
I want to use the System.Drawing.Image class. According to the help
file,
this is an abstract base class. Because it is supposedly abstract, I
created
another class that inherits from it. However, when I did this I got the
following error:
'System.Drawing.Image.Image()' is inaccessible due to its protection
level
Looking at other online examples, I found that the proper way to use it
is
like this:
System.Drawing.Image Jpg = System.Drawing.Image.FromFile(PathToFile);
If this is an abstract base class, why can't I inherit from it and why
am
I
able to instantiate it as in the immediately above statement?