473,732 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is image and Bitmap a sealed class?

Why did microsoft seal these classes? I would like to add coordinate
information to these classes but I can't derive from them ;/ It makes me
wonder why microsft choose to prevent anyone from deriving from many
classes.

I can simply do

class MyBitmap
{
public Bitmap B;
public Point Loc;
....
}

But why do they not want me to do

class MyBitmap : Bitmap
{
public Point Loc;
....
}

?

It seems to make it easier to work with the second case than the first and
I'm wondering what MS's motivation for doing what they did.

Thanks,
Jon
Oct 17 '06 #1
5 3169
"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:12******** *****@corp.supe rnews.com...
Why did microsoft seal these classes? I would like to add coordinate
information to these classes but I can't derive from them ;/ It makes me
wonder why microsft choose to prevent anyone from deriving from many
classes.
I've asked this same questoion before because I wanted to add a property to
a bitmap just to tag some extra information along with it. The answer was it
is difficult to make a class inheritable. It exposes a lot of internal
functionality and the effects need to be taken into account. For example,
someone might override a method and returning an unexpected result could
cause a gpf, so they need to take this in to account to avoid a gpf. They
could have allowed it to be inheritable and provided no virtual or protected
methods but then everyone would complain about that. :-)

Michael
Oct 18 '06 #2
Yep. Then you need to look into "Plan B". This might be, create a custom
class that has a Bitmap as a field,along with all the cool extra "Stuff" that
you want.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jon Slaughter" wrote:
Why did microsoft seal these classes? I would like to add coordinate
information to these classes but I can't derive from them ;/ It makes me
wonder why microsft choose to prevent anyone from deriving from many
classes.

I can simply do

class MyBitmap
{
public Bitmap B;
public Point Loc;
....
}

But why do they not want me to do

class MyBitmap : Bitmap
{
public Point Loc;
....
}

?

It seems to make it easier to work with the second case than the first and
I'm wondering what MS's motivation for doing what they did.

Thanks,
Jon
Oct 18 '06 #3
I've asked this same questoion before because I wanted to add a property to
a bitmap just to tag some extra information along with it. The answer was it
is difficult to make a class inheritable. It exposes a lot of internal
functionality and the effects need to be taken into account. For example,
someone might override a method and returning an unexpected result could
cause a gpf, so they need to take this in to account to avoid a gpf. They
could have allowed it to be inheritable and provided no virtual or protected
methods but then everyone would complain about that. :-)
That seems to be a bit like saying "Lets remove the while loop because
someone could do a while(true) {}
While I appreciate that it wasn't actually your answer, I have to
believe that it should be up to the programmer to make those mistakes,
learn from them, and in turn become better at it, rather than just
restricting access to the inheritance of the class. Microsoft shouldn't
make my programming choices for me...

Oct 18 '06 #4
"Steven Nagy" <le*********@ho tmail.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
That seems to be a bit like saying "Lets remove the while loop because
someone could do a while(true) {}
While I appreciate that it wasn't actually your answer,
In this case the result is not a gpf.
I have to
believe that it should be up to the programmer to make those mistakes,
learn from them, and in turn become better at it, rather than just
restricting access to the inheritance of the class. Microsoft shouldn't
make my programming choices for me...
One of the criterias for a component for .net appears to be that it should
be impossible to make it gpf (or at least difficult). This might not have
been possible if inheriting the bitmap class or might have been difficult.
On one hand I do agree that it's good to be able to do what you want it
would also be a pain to have a gpf on the odd occassion when an app was
released. That would be a complete bugger to find so I'd probably prefer to
have the non-inheritable bitmap.

That being said, I'd prefer to have a stable, inheritable bitmap :-)

Michael
Oct 18 '06 #5

Aka,,,something along the lines of:
The Proxy Design Pattern.

http://www.dofactory.com/Patterns/PatternProxy.aspx

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com wrote in message
news:0D******** *************** ***********@mic rosoft.com...
Yep. Then you need to look into "Plan B". This might be, create a custom
class that has a Bitmap as a field,along with all the cool extra "Stuff"
that
you want.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jon Slaughter" wrote:
Why did microsoft seal these classes? I would like to add coordinate
information to these classes but I can't derive from them ;/ It makes me
wonder why microsft choose to prevent anyone from deriving from many
classes.

I can simply do

class MyBitmap
{
public Bitmap B;
public Point Loc;
....
}

But why do they not want me to do

class MyBitmap : Bitmap
{
public Point Loc;
....
}

?

It seems to make it easier to work with the second case than the first
and
I'm wondering what MS's motivation for doing what they did.

Thanks,
Jon


Oct 18 '06 #6

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

Similar topics

3
6103
by: Marcin Kowalewski | last post by:
Hi I've got a stupid problem with code below : using System; using System.Drawing; .... public class CsrcImage :Image { public CsrcImage() { //
8
2034
by: Dave Quigley | last post by:
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...
6
2949
by: anonymous | last post by:
hi all, I'm trying to use the capCreateCaptureWindow (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_capcreatecapturewindow.asp) in a Windows Application Project. I want to pass Image as one of the parameter but I figure that an Image doesn't have a handle. Previously I had it working in a Web Application Project using the handle of a PictureBox. Is there any workaround? Please help and...
4
2754
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
4
1647
by: Jon Slaughter | last post by:
Whats is there any reason to use a Bitmap(Image) over an Image(Bitmap)? I'm making a container to hold bitmaps sorta like the ImageList class(that doesn't fix the sizes) but I'm not sure if I should use Images or Bitmaps? I don't know of the real distinction between them excep that the Bitmap class allows you lower level access to the image data and stuff(but does it come at a price)? Thanks, Jon
0
2881
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is below: chartGenerator.vb class: Imports System.Drawing.Imaging Public Class chartGenerator Private myImage As Bitmap
1
3795
by: rsteph | last post by:
I bought a book to help me learn to use DirectX with windows programming. It's first trying to walk me through some basic windows programming and graphics before getting into DirectX. I'm trying to expand on one of the example programs in the book but I'm having some problems. I can get a frame to appear, then an image gets randomly placed in the box. It is suppose to move right, then when it hits the edge move left; it should repeate this...
2
2937
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...
2
2816
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a "Graphics" object to wrap around the image (!). It's not so simple as shown in most examples (where they have a simple image file and hard copy it into a harddrive along the lines of : image.Save(@"C:\\temp\\myimage.pgn"); That will work, but it's a...
0
8774
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,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
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...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
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.