PC Review


Reply
Thread Tools Rate Thread

Adding Image file supports into .net

 
 
Dave Quigley
Guest
Posts: n/a
 
      4th Jan 2004
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


 
Reply With Quote
 
 
 
 
Chris Taylor
Guest
Posts: n/a
 
      4th Jan 2004
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%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Dave Quigley
Guest
Posts: n/a
 
      4th Jan 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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%(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      4th Jan 2004
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:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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%(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      4th Jan 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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%(E-Mail Removed)...
> > > > 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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Dave Quigley
Guest
Posts: n/a
 
      4th Jan 2004
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" <(E-Mail Removed)> wrote in message
news:eE$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > 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%(E-Mail Removed)...
> > > > > 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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      5th Jan 2004


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!
 
Reply With Quote
 
Dave Quigley
Guest
Posts: n/a
 
      5th Jan 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> 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!



 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      5th Jan 2004
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:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> >
> > 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!

>
>



 
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
Adding hidden image file data JJ Microsoft ASP .NET 2 23rd Jul 2008 09:24 PM
adding a tag to a jpeg image file Mark Harris Microsoft C# .NET 1 29th Feb 2008 08:10 PM
adding .JPG image to FrontPage getting file format not supported? =?Utf-8?B?UGhvdG9ndXk=?= Microsoft Frontpage 2 7th Feb 2007 06:53 PM
adding the file/properties window to a existing image kbodily@charter.net Windows XP Embedded 1 9th May 2006 07:47 AM
Adding an image (icon) to a RESX file =?Utf-8?B?U3RldmUgVGVlcGxlcw==?= Microsoft C# .NET 0 20th May 2005 07:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:31 AM.