467,132 Members | 1,138 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,132 developers. It's quick & easy.

confused with the use of System.Drawing.Image


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?
Sep 3 '06 #1
  • viewed: 2941
Share:
5 Replies
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**********************************@microsof t.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?


Sep 3 '06 #2
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**********************************@microsof t.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?


Sep 4 '06 #3

Jerry J wrote:
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**********************************@microsof t.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?
You haven't instantiated it. You've called a static method, FromFile,
that returns a subclass of System.Drawing.Image, which you've assigned
to a base class reference (which is perfectly legal O-O). Try this:

System.Drawing.Image jpg = System.Drawing.Image.FromFile(PathToFile);
MessageBox.Show(String.Format("jpg type is {0}", jpg.GetType());

I think you'll see that the type is something other than "Image".

Sep 4 '06 #4
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?




Sep 4 '06 #5
OK, I understand now. I do think the Microsoft Help is a bit unclear. Thank
you for the info Bruce and Nicholas.
--
Jerry J
"Jerry J" wrote:
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**********************************@microsof t.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?
>
>
Sep 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Toby Mathews | last post: by
2 posts views Thread by SamSpade | last post: by
reply views Thread by John via .NET 247 | last post: by
7 posts views Thread by Leszek L. | last post: by
2 posts views Thread by ThatsIT.net.au | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.