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!