PC Review


Reply
Thread Tools Rate Thread

confused with the use of System.Drawing.Image

 
 
=?Utf-8?B?SmVycnkgSg==?=
Guest
Posts: n/a
 
      3rd Sep 2006

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?


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      3rd Sep 2006
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]
- (E-Mail Removed)

"Jerry J" <(E-Mail Removed)> wrote in message
news:1316D207-4FD2-47E6-AF65-(E-Mail Removed)...
>
> 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?
>
>



 
Reply With Quote
 
=?Utf-8?B?SmVycnkgSg==?=
Guest
Posts: n/a
 
      4th Sep 2006
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]
> - (E-Mail Removed)
>
> "Jerry J" <(E-Mail Removed)> wrote in message
> news:1316D207-4FD2-47E6-AF65-(E-Mail Removed)...
> >
> > 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?
> >
> >

>
>
>

 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      4th Sep 2006

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]
> > - (E-Mail Removed)
> >
> > "Jerry J" <(E-Mail Removed)> wrote in message
> > news:1316D207-4FD2-47E6-AF65-(E-Mail Removed)...
> > >
> > > 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".

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      4th Sep 2006
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]
- (E-Mail Removed)

"Jerry J" <(E-Mail Removed)> wrote in message
news:37A48E7D-1989-475D-ACAB-(E-Mail Removed)...
>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]
>> - (E-Mail Removed)
>>
>> "Jerry J" <(E-Mail Removed)> wrote in message
>> news:1316D207-4FD2-47E6-AF65-(E-Mail Removed)...
>> >
>> > 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?
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?SmVycnkgSg==?=
Guest
Posts: n/a
 
      4th Sep 2006
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]
> > - (E-Mail Removed)
> >
> > "Jerry J" <(E-Mail Removed)> wrote in message
> > news:1316D207-4FD2-47E6-AF65-(E-Mail Removed)...
> > >
> > > 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?
> > >
> > >

> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mirror / rotate image ( System.Drawing.Graphics / System.Drawing.Drawing2D.Matrix) Eduard Witteveen Microsoft C# .NET 3 17th Jul 2006 01:26 PM
system.drawing.image to system.web.ui.webcontrols.image byrd48 Microsoft ASP .NET 0 6th Jul 2006 05:02 AM
System.drawing.image =?Utf-8?B?YmVub2l0?= Microsoft ASP .NET 5 23rd Jan 2006 01:00 PM
System.Drawing.Image and jpg images FlyFishGuy Microsoft Dot NET Framework 1 18th Jan 2006 02:23 AM
StdPicture to System.Drawing.Image ??? Curtis Tammany Microsoft Dot NET 0 9th Oct 2003 07:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 AM.