Connecting Tech Pros Worldwide Forums | Help | Site Map

Adding Image file supports into .net

Dave Quigley
Guest
 
Posts: n/a
#1: Nov 15 '05
Hello everyone.... Im currently starting my targa support project again for
..NET and I am wondering if there are any particular interfaces or classes
that Im supposed to extend in order to do this in a propper manner. I could
try to replicate Bitmap however I believe the problem I ran into was that
the base classes for images are sealed in .net so I cant inherit from
them... Any suggestions would be greatly apprectiated. I may consider adding
things like psd support also later down the line so I want to come up with a
system now.

Dave Quigley



Chris Taylor
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Adding Image file supports into .net


The .NET Image class is not sealed.

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"Dave Quigley" <merlin at countercultured dot net> wrote in message
news:uKmm3%23p0DHA.1760@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hello everyone.... Im currently starting my targa support project again[/color]
for[color=blue]
> .NET and I am wondering if there are any particular interfaces or classes
> that Im supposed to extend in order to do this in a propper manner. I[/color]
could[color=blue]
> try to replicate Bitmap however I believe the problem I ran into was that
> the base classes for images are sealed in .net so I cant inherit from
> them... Any suggestions would be greatly apprectiated. I may consider[/color]
adding[color=blue]
> things like psd support also later down the line so I want to come up with[/color]
a[color=blue]
> system now.
>
> Dave Quigley
>
>[/color]


Dave Quigley
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Adding Image file supports into .net


I realized that while looking through the documentation so I must be missing
something then... This is what I have for the class declaration

public class Targa : Image
{
public Targa()
{
}
}
Very simple but its giving me this error.


System.Drawing.Image.Image() is inaccessable due to its protection level. Im
not quite sure why its looking for this constructor since the base class is
abstract so it shouldent exist.

This does however pose a problem. If I inherit from Image which seems to be
the best Idea how do I go about getting the information to the graphic
object properly... I was thinking a bitmap data object internally which I
can probably just pass to be drawn.. That makes the most sense to me... Its
either do it this way or write Targa as a wrapper around Bitmap for encoding
and decoding targas. Im not quite sure the best way to do this.


"Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
news:OK0EWLq0DHA.208@TK2MSFTNGP12.phx.gbl...[color=blue]
> The .NET Image class is not sealed.
>
> --
> Chris Taylor
> http://www.xanga.com/home.aspx?user=taylorza
> "Dave Quigley" <merlin at countercultured dot net> wrote in message
> news:uKmm3%23p0DHA.1760@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hello everyone.... Im currently starting my targa support project again[/color]
> for[color=green]
> > .NET and I am wondering if there are any particular interfaces or[/color][/color]
classes[color=blue][color=green]
> > that Im supposed to extend in order to do this in a propper manner. I[/color]
> could[color=green]
> > try to replicate Bitmap however I believe the problem I ran into was[/color][/color]
that[color=blue][color=green]
> > the base classes for images are sealed in .net so I cant inherit from
> > them... Any suggestions would be greatly apprectiated. I may consider[/color]
> adding[color=green]
> > things like psd support also later down the line so I want to come up[/color][/color]
with[color=blue]
> a[color=green]
> > system now.
> >
> > Dave Quigley
> >
> >[/color]
>
>[/color]


Chris Taylor
Guest
 
Posts: n/a
#4: Nov 15 '05

re: Adding Image file supports into .net


Hi,

The constructor of the Image class is internal, that way any classes within
the same Assembly such as Bitmap can happily derive from image. What might
be an option for you (And I have not tried this!), is to write your own
class Targa, then to provide a implicit cast operator for Image or Bitmap.
That way you can pass your class into functions that require a Image. I will
do a test to see if something like this will work and post my results here.

Hope this helps

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"Dave Quigley" <merlin at countercultured dot net> wrote in message
news:OQn82Xq0DHA.3496@TK2MSFTNGP11.phx.gbl...[color=blue]
> I realized that while looking through the documentation so I must be[/color]
missing[color=blue]
> something then... This is what I have for the class declaration
>
> public class Targa : Image
> {
> public Targa()
> {
> }
> }
> Very simple but its giving me this error.
>
>
> System.Drawing.Image.Image() is inaccessable due to its protection level.[/color]
Im[color=blue]
> not quite sure why its looking for this constructor since the base class[/color]
is[color=blue]
> abstract so it shouldent exist.
>
> This does however pose a problem. If I inherit from Image which seems to[/color]
be[color=blue]
> the best Idea how do I go about getting the information to the graphic
> object properly... I was thinking a bitmap data object internally which I
> can probably just pass to be drawn.. That makes the most sense to me...[/color]
Its[color=blue]
> either do it this way or write Targa as a wrapper around Bitmap for[/color]
encoding[color=blue]
> and decoding targas. Im not quite sure the best way to do this.
>
>
> "Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
> news:OK0EWLq0DHA.208@TK2MSFTNGP12.phx.gbl...[color=green]
> > The .NET Image class is not sealed.
> >
> > --
> > Chris Taylor
> > http://www.xanga.com/home.aspx?user=taylorza
> > "Dave Quigley" <merlin at countercultured dot net> wrote in message
> > news:uKmm3%23p0DHA.1760@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > Hello everyone.... Im currently starting my targa support project[/color][/color][/color]
again[color=blue][color=green]
> > for[color=darkred]
> > > .NET and I am wondering if there are any particular interfaces or[/color][/color]
> classes[color=green][color=darkred]
> > > that Im supposed to extend in order to do this in a propper manner. I[/color]
> > could[color=darkred]
> > > try to replicate Bitmap however I believe the problem I ran into was[/color][/color]
> that[color=green][color=darkred]
> > > the base classes for images are sealed in .net so I cant inherit from
> > > them... Any suggestions would be greatly apprectiated. I may consider[/color]
> > adding[color=darkred]
> > > things like psd support also later down the line so I want to come up[/color][/color]
> with[color=green]
> > a[color=darkred]
> > > system now.
> > >
> > > Dave Quigley
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Chris Taylor
Guest
 
Posts: n/a
#5: Nov 15 '05

re: Adding Image file supports into .net


Hi,

I did the following little test to confirm my previous post.

class MyImage
{
private string _fileName;
private Bitmap _bitmap;

public MyImage( string fileName )
{
_fileName = fileName;
}

public static implicit operator Image( MyImage o )
{
if ( o._bitmap == null )
o._bitmap = new Bitmap( o._fileName );

return o._bitmap;
}
}

Then in my Paint event handler

MyImage img = new MyImage("c:\\winnt\\Soap Bubbles.bmp");
e.Graphics.DrawImage( img, 0, 0 );

Hope this helps

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
news:eI0Dxlq0DHA.3140@tk2msftngp13.phx.gbl...[color=blue]
> Hi,
>
> The constructor of the Image class is internal, that way any classes[/color]
within[color=blue]
> the same Assembly such as Bitmap can happily derive from image. What might
> be an option for you (And I have not tried this!), is to write your own
> class Targa, then to provide a implicit cast operator for Image or Bitmap.
> That way you can pass your class into functions that require a Image. I[/color]
will[color=blue]
> do a test to see if something like this will work and post my results[/color]
here.[color=blue]
>
> Hope this helps
>
> --
> Chris Taylor
> http://www.xanga.com/home.aspx?user=taylorza
> "Dave Quigley" <merlin at countercultured dot net> wrote in message
> news:OQn82Xq0DHA.3496@TK2MSFTNGP11.phx.gbl...[color=green]
> > I realized that while looking through the documentation so I must be[/color]
> missing[color=green]
> > something then... This is what I have for the class declaration
> >
> > public class Targa : Image
> > {
> > public Targa()
> > {
> > }
> > }
> > Very simple but its giving me this error.
> >
> >
> > System.Drawing.Image.Image() is inaccessable due to its protection[/color][/color]
level.[color=blue]
> Im[color=green]
> > not quite sure why its looking for this constructor since the base class[/color]
> is[color=green]
> > abstract so it shouldent exist.
> >
> > This does however pose a problem. If I inherit from Image which seems to[/color][/color]
[color=blue]
> be[color=green]
> > the best Idea how do I go about getting the information to the graphic
> > object properly... I was thinking a bitmap data object internally which[/color][/color]
I[color=blue][color=green]
> > can probably just pass to be drawn.. That makes the most sense to me...[/color]
> Its[color=green]
> > either do it this way or write Targa as a wrapper around Bitmap for[/color]
> encoding[color=green]
> > and decoding targas. Im not quite sure the best way to do this.
> >
> >
> > "Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
> > news:OK0EWLq0DHA.208@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > The .NET Image class is not sealed.
> > >
> > > --
> > > Chris Taylor
> > > http://www.xanga.com/home.aspx?user=taylorza
> > > "Dave Quigley" <merlin at countercultured dot net> wrote in message
> > > news:uKmm3%23p0DHA.1760@TK2MSFTNGP10.phx.gbl...
> > > > Hello everyone.... Im currently starting my targa support project[/color][/color]
> again[color=green][color=darkred]
> > > for
> > > > .NET and I am wondering if there are any particular interfaces or[/color]
> > classes[color=darkred]
> > > > that Im supposed to extend in order to do this in a propper manner.[/color][/color][/color]
I[color=blue][color=green][color=darkred]
> > > could
> > > > try to replicate Bitmap however I believe the problem I ran into was[/color]
> > that[color=darkred]
> > > > the base classes for images are sealed in .net so I cant inherit[/color][/color][/color]
from[color=blue][color=green][color=darkred]
> > > > them... Any suggestions would be greatly apprectiated. I may[/color][/color][/color]
consider[color=blue][color=green][color=darkred]
> > > adding
> > > > things like psd support also later down the line so I want to come[/color][/color][/color]
up[color=blue][color=green]
> > with[color=darkred]
> > > a
> > > > system now.
> > > >
> > > > Dave Quigley
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Dave Quigley
Guest
 
Posts: n/a
#6: Nov 15 '05

re: Adding Image file supports into .net


Thats kewl,

Could you explain the implicit operator a bit more Ive never seen it used
and I want to make sure I fully understand it before I go ahead and use it.

"Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
news:eE$wYqq0DHA.556@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi,
>
> I did the following little test to confirm my previous post.
>
> class MyImage
> {
> private string _fileName;
> private Bitmap _bitmap;
>
> public MyImage( string fileName )
> {
> _fileName = fileName;
> }
>
> public static implicit operator Image( MyImage o )
> {
> if ( o._bitmap == null )
> o._bitmap = new Bitmap( o._fileName );
>
> return o._bitmap;
> }
> }
>
> Then in my Paint event handler
>
> MyImage img = new MyImage("c:\\winnt\\Soap Bubbles.bmp");
> e.Graphics.DrawImage( img, 0, 0 );
>
> Hope this helps
>
> --
> Chris Taylor
> http://www.xanga.com/home.aspx?user=taylorza
> "Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
> news:eI0Dxlq0DHA.3140@tk2msftngp13.phx.gbl...[color=green]
> > Hi,
> >
> > The constructor of the Image class is internal, that way any classes[/color]
> within[color=green]
> > the same Assembly such as Bitmap can happily derive from image. What[/color][/color]
might[color=blue][color=green]
> > be an option for you (And I have not tried this!), is to write your own
> > class Targa, then to provide a implicit cast operator for Image or[/color][/color]
Bitmap.[color=blue][color=green]
> > That way you can pass your class into functions that require a Image. I[/color]
> will[color=green]
> > do a test to see if something like this will work and post my results[/color]
> here.[color=green]
> >
> > Hope this helps
> >
> > --
> > Chris Taylor
> > http://www.xanga.com/home.aspx?user=taylorza
> > "Dave Quigley" <merlin at countercultured dot net> wrote in message
> > news:OQn82Xq0DHA.3496@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > I realized that while looking through the documentation so I must be[/color]
> > missing[color=darkred]
> > > something then... This is what I have for the class declaration
> > >
> > > public class Targa : Image
> > > {
> > > public Targa()
> > > {
> > > }
> > > }
> > > Very simple but its giving me this error.
> > >
> > >
> > > System.Drawing.Image.Image() is inaccessable due to its protection[/color][/color]
> level.[color=green]
> > Im[color=darkred]
> > > not quite sure why its looking for this constructor since the base[/color][/color][/color]
class[color=blue][color=green]
> > is[color=darkred]
> > > abstract so it shouldent exist.
> > >
> > > This does however pose a problem. If I inherit from Image which seems[/color][/color][/color]
to[color=blue]
>[color=green]
> > be[color=darkred]
> > > the best Idea how do I go about getting the information to the graphic
> > > object properly... I was thinking a bitmap data object internally[/color][/color][/color]
which[color=blue]
> I[color=green][color=darkred]
> > > can probably just pass to be drawn.. That makes the most sense to[/color][/color][/color]
me...[color=blue][color=green]
> > Its[color=darkred]
> > > either do it this way or write Targa as a wrapper around Bitmap for[/color]
> > encoding[color=darkred]
> > > and decoding targas. Im not quite sure the best way to do this.
> > >
> > >
> > > "Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
> > > news:OK0EWLq0DHA.208@TK2MSFTNGP12.phx.gbl...
> > > > The .NET Image class is not sealed.
> > > >
> > > > --
> > > > Chris Taylor
> > > > http://www.xanga.com/home.aspx?user=taylorza
> > > > "Dave Quigley" <merlin at countercultured dot net> wrote in message
> > > > news:uKmm3%23p0DHA.1760@TK2MSFTNGP10.phx.gbl...
> > > > > Hello everyone.... Im currently starting my targa support project[/color]
> > again[color=darkred]
> > > > for
> > > > > .NET and I am wondering if there are any particular interfaces or
> > > classes
> > > > > that Im supposed to extend in order to do this in a propper[/color][/color][/color]
manner.[color=blue]
> I[color=green][color=darkred]
> > > > could
> > > > > try to replicate Bitmap however I believe the problem I ran into[/color][/color][/color]
was[color=blue][color=green][color=darkred]
> > > that
> > > > > the base classes for images are sealed in .net so I cant inherit[/color][/color]
> from[color=green][color=darkred]
> > > > > them... Any suggestions would be greatly apprectiated. I may[/color][/color]
> consider[color=green][color=darkred]
> > > > adding
> > > > > things like psd support also later down the line so I want to come[/color][/color]
> up[color=green][color=darkred]
> > > with
> > > > a
> > > > > system now.
> > > > >
> > > > > Dave Quigley
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Chris Taylor
Guest
 
Posts: n/a
#7: Nov 15 '05

re: Adding Image file supports into .net




Hi Dave,

When providing an cast operator it can either be as explicit or
implicit. An explicit cast operator requires that the user explicitly
cast. So had I declared the cast operator as explicit then the call to
drawing would have been as follows.

e.Graphics.DrawImage( (Image)img, 0, 0 );

The above is still valid for the implicit cast operator, so there is no
need to declare both (in fact you get a compile error if you do).

<IMHO>
The question of course is if this is really a good design practice,
personally I try to avoid operator overloads unless they really make
sense. For me the risk of the above is that I get the false impression
that the MyImage class is derived from Image. On the other hand if it
can be pulled of seamlessly and the user of your library can reuse his
knowlege of Image and Bitmap classes it could be worth while. One way to
do this might be to provide the same interface to your class as what
Image has, if you can do that I think it would be great (Again, just my
opinion).

I assume that your implementation of the Targa loader will actually
build a bitmap and convert from the Targa file format to the in memory
Bitmap. If so then you can provide the same interface as Image and
delegate the calls to the underlying Bitmap created by the loader. I
think that would take you a very long way in accurately emulating the
Microsoft Image/Bitmap classes. You can hopefully also provide a
non-specific base class so that other image file formats can be
developed from your framework.
</IMHO>

Hope this helps

Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Dave Quigley
Guest
 
Posts: n/a
#8: Nov 15 '05

re: Adding Image file supports into .net


Thanks for your input. After thinking about this for a good portion of today
I decided that since images such as png's jpeg's and gif's get turned into
bitmaps internally for the purposes of .net why just not write a set of
encoders and decoders instead. This will allow me to just write encoders and
decoders for targa and do all my filtering and such on the bitmap objects
directly which makes more sense to me.

Dave

"Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
news:OBQ10v20DHA.1184@TK2MSFTNGP10.phx.gbl...[color=blue]
>
>
> Hi Dave,
>
> When providing an cast operator it can either be as explicit or
> implicit. An explicit cast operator requires that the user explicitly
> cast. So had I declared the cast operator as explicit then the call to
> drawing would have been as follows.
>
> e.Graphics.DrawImage( (Image)img, 0, 0 );
>
> The above is still valid for the implicit cast operator, so there is no
> need to declare both (in fact you get a compile error if you do).
>
> <IMHO>
> The question of course is if this is really a good design practice,
> personally I try to avoid operator overloads unless they really make
> sense. For me the risk of the above is that I get the false impression
> that the MyImage class is derived from Image. On the other hand if it
> can be pulled of seamlessly and the user of your library can reuse his
> knowlege of Image and Bitmap classes it could be worth while. One way to
> do this might be to provide the same interface to your class as what
> Image has, if you can do that I think it would be great (Again, just my
> opinion).
>
> I assume that your implementation of the Targa loader will actually
> build a bitmap and convert from the Targa file format to the in memory
> Bitmap. If so then you can provide the same interface as Image and
> delegate the calls to the underlying Bitmap created by the loader. I
> think that would take you a very long way in accurately emulating the
> Microsoft Image/Bitmap classes. You can hopefully also provide a
> non-specific base class so that other image file formats can be
> developed from your framework.
> </IMHO>
>
> Hope this helps
>
> Chris Taylor
> http://www.xanga.com/home.aspx?user=taylorza
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]


Chris Taylor
Guest
 
Posts: n/a
#9: Nov 15 '05

re: Adding Image file supports into .net


Hi,

It is a pleasure!

For the benefit of this thread and group, I just want to highlight that the
documentation is incorrect or rather misleading in that it is implied that
the System.Drawing.Imaging.Encoder class enables one to develop custom
CODECS for the GDI+ imaging system. This is unfortunately not supported in
the current version of GDI+, not for .NET v1.0 or .NET v1.1. So your
encoder/decoder will have to be a component that returns a Bitmap. Which I
am sure is what you intended, I just wanted to clarify this point.

Hopefully Microsoft will provide this extensibility in the future.

Regards

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"Dave Quigley" <merlin at countercultured dot net> wrote in message
news:%23vr2a720DHA.1908@TK2MSFTNGP10.phx.gbl...[color=blue]
> Thanks for your input. After thinking about this for a good portion of[/color]
today[color=blue]
> I decided that since images such as png's jpeg's and gif's get turned into
> bitmaps internally for the purposes of .net why just not write a set of
> encoders and decoders instead. This will allow me to just write encoders[/color]
and[color=blue]
> decoders for targa and do all my filtering and such on the bitmap objects
> directly which makes more sense to me.
>
> Dave
>
> "Chris Taylor" <chris_taylor_za@hotmail.com> wrote in message
> news:OBQ10v20DHA.1184@TK2MSFTNGP10.phx.gbl...[color=green]
> >
> >
> > Hi Dave,
> >
> > When providing an cast operator it can either be as explicit or
> > implicit. An explicit cast operator requires that the user explicitly
> > cast. So had I declared the cast operator as explicit then the call to
> > drawing would have been as follows.
> >
> > e.Graphics.DrawImage( (Image)img, 0, 0 );
> >
> > The above is still valid for the implicit cast operator, so there is no
> > need to declare both (in fact you get a compile error if you do).
> >
> > <IMHO>
> > The question of course is if this is really a good design practice,
> > personally I try to avoid operator overloads unless they really make
> > sense. For me the risk of the above is that I get the false impression
> > that the MyImage class is derived from Image. On the other hand if it
> > can be pulled of seamlessly and the user of your library can reuse his
> > knowlege of Image and Bitmap classes it could be worth while. One way to
> > do this might be to provide the same interface to your class as what
> > Image has, if you can do that I think it would be great (Again, just my
> > opinion).
> >
> > I assume that your implementation of the Targa loader will actually
> > build a bitmap and convert from the Targa file format to the in memory
> > Bitmap. If so then you can provide the same interface as Image and
> > delegate the calls to the underlying Bitmap created by the loader. I
> > think that would take you a very long way in accurately emulating the
> > Microsoft Image/Bitmap classes. You can hopefully also provide a
> > non-specific base class so that other image file formats can be
> > developed from your framework.
> > </IMHO>
> >
> > Hope this helps
> >
> > Chris Taylor
> > http://www.xanga.com/home.aspx?user=taylorza
> >
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it![/color]
>
>[/color]


Closed Thread