473,837 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Image file supports into .net

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
Nov 15 '05 #1
8 2036
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:uK******** ********@TK2MSF TNGP10.phx.gbl. ..
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

Nov 15 '05 #2
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" <ch************ *@hotmail.com> wrote in message
news:OK******** *****@TK2MSFTNG P12.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:uK******** ********@TK2MSF TNGP10.phx.gbl. ..
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


Nov 15 '05 #3
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:OQ******** ******@TK2MSFTN GP11.phx.gbl...
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" <ch************ *@hotmail.com> wrote in message
news:OK******** *****@TK2MSFTNG P12.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:uK******** ********@TK2MSF TNGP10.phx.gbl. ..
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



Nov 15 '05 #4
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:\\wi nnt\\Soap Bubbles.bmp");
e.Graphics.Draw Image( img, 0, 0 );

Hope this helps

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"Chris Taylor" <ch************ *@hotmail.com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
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:OQ******** ******@TK2MSFTN GP11.phx.gbl...
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" <ch************ *@hotmail.com> wrote in message
news:OK******** *****@TK2MSFTNG P12.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:uK******** ********@TK2MSF TNGP10.phx.gbl. ..
> 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
>
>



Nov 15 '05 #5
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" <ch************ *@hotmail.com> wrote in message
news:eE******** *****@TK2MSFTNG P11.phx.gbl...
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:\\wi nnt\\Soap Bubbles.bmp");
e.Graphics.Draw Image( img, 0, 0 );

Hope this helps

--
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
"Chris Taylor" <ch************ *@hotmail.com> wrote in message
news:eI******** ******@tk2msftn gp13.phx.gbl...
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:OQ******** ******@TK2MSFTN GP11.phx.gbl...
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" <ch************ *@hotmail.com> wrote in message
news:OK******** *****@TK2MSFTNG P12.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:uK******** ********@TK2MSF TNGP10.phx.gbl. ..
> > 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
> >
> >
>
>



Nov 15 '05 #6


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.Draw Image( (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!
Nov 15 '05 #7
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" <ch************ *@hotmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl...


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.Draw Image( (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!

Nov 15 '05 #8
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:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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" <ch************ *@hotmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl...


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.Draw Image( (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!


Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
24232
by: deko | last post by:
I have a table that contains a bunch of pictures. When the user selects a particular image in a form, I need a way to extract the selected bitmap image (stored in an OLE Object table field) to the file system so the user can do stuff with "somePicture.bmp", for example. Is there an easy way to do this? Thanks in advance.
10
7415
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't recommend storing the image to the filesystem and only keeping a pointer to that in the table. I want to dump the image to a table. My code dumps the data into the table, however, I get the following error when trying to view the image "the image ......
3
2748
by: Simon Harris | last post by:
Hi All, I have a data grid which displays country names. I now wish to display the country flag images above the names. Can someone please advise how I display an image in a datagrid? I have a folder of flag images, named in relations to the countries database ID. Current data grid code is...
3
1499
by: Csaba Gabor | last post by:
Not sure of best place for this question... Are there any built in images within the browser that I can assume (particularly IE and FF)? More specifically, I am writing a one file webApp.php application which needs one tiny little folder icon (e.g. http://us.geo1.yimg.com/pic.geocities.com/img/filemgr/folder.gif). Now I could have a second file of the folder icon, but I would rather only have one text file to distribute (namely,...
4
3470
by: LT.Ang | last post by:
I am developing an application that possibly opens very large images - bmp, jpeg, tiff. I have 2 questions: Language: C#, VS .NET 2003. 1. When the program opens a BMP image, the amount of memory used seems to be larger for BMP files than JPEGs with the same pixel dimensions. For example, 5200 x 5000 pixels image -- increase in Mem Usage is about 80MB for JPEG, but 200MB for BMP (with Task Manager). The Mem Usage is noted before and...
2
2941
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file formats are supported in this way? Is this fixed based on the .NET Framework used (e.g., the Image class defines which formats can be used), or can different file formats be added after-the-fact (end-user capability in contrast to developer implementation)? Also, is it possible to save an image in...
5
8817
by: Peted | last post by:
Ive seen on the web third party componets such as custom buttons and guages and dashboard graphics in controls that graphicaly look realy good. I was wonderinghow they do thos great looking controls. I know its possible to produce custom controls with GDI+ to draw the gpahics, but it would seem almost impossible to draw some of the realy complex controls ive seen.
2
3236
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of StringIO objects being passed in place of file objects. StringIO objects are binary strings of variable length that are kept in memory so i saved the image in stringio objects the following code does that file = StringIO() image.save(file, "JPEG") ...
1
11104
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of StringIO objects being passed in place of file objects. StringIO objects are binary strings of variable length that are kept in memory so i saved the image in stringio objects the following code does that for gif image ...
0
9843
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10623
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10272
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5669
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.