473,581 Members | 2,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The ColorPalette class has no constructor so how does one use it?

The ColorPalette class has no constructor so how does one use it?
I define a variable by:

Dim cp as ColorPalette

but don't know how assign an object to the variable.

Thanks in advance


Jul 14 '07 #1
19 2414
On Sat, 14 Jul 2007 13:49:13 -0400, " active"
<ac********** @a-znet.comwrote:
>The ColorPalette class has no constructor so how does one use it?
I define a variable by:

Dim cp as ColorPalette

but don't know how assign an object to the variable.
If there is no constructor, then you can only get a ColorPalette from
other objects. For example:

Dim cp As ColorPalette
Dim bmp As Bitmap = New Bitmap("figure2 .bmp")

cp = bmp.Palette
Jul 14 '07 #2
Lke the other poster says...

Just create a 1x1 bitmap of the appropriate bit depth and retrieve it's
color palette into your variable.

It's not elegant, but it's the only way.

" active" <ac********** @a-znet.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
The ColorPalette class has no constructor so how does one use it?
I define a variable by:

Dim cp as ColorPalette

but don't know how assign an object to the variable.

Thanks in advance



Jul 14 '07 #3
thanks

"Jack Jackson" <ja********@peb bleridge.comwro te in message
news:nm******** *************** *********@4ax.c om...
On Sat, 14 Jul 2007 13:49:13 -0400, " active"
<ac********** @a-znet.comwrote:
>>The ColorPalette class has no constructor so how does one use it?
I define a variable by:

Dim cp as ColorPalette

but don't know how assign an object to the variable.

If there is no constructor, then you can only get a ColorPalette from
other objects. For example:

Dim cp As ColorPalette
Dim bmp As Bitmap = New Bitmap("figure2 .bmp")

cp = bmp.Palette

Jul 14 '07 #4
thanks

"Blake" <no@emailwrot e in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Lke the other poster says...

Just create a 1x1 bitmap of the appropriate bit depth and retrieve it's
color palette into your variable.

It's not elegant, but it's the only way.

" active" <ac********** @a-znet.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>The ColorPalette class has no constructor so how does one use it?
I define a variable by:

Dim cp as ColorPalette

but don't know how assign an object to the variable.

Thanks in advance




Jul 14 '07 #5

What do you need it for anyway?

The ColorPalette class is just a wrapper for a simple
1-dimensional array of System.Drawing. Color entries.

It contains two internal (Friend) methods:
- ConvertFromMemo ry
- ConvertToMemory

All they do is to convert between 32-bit integers and
System.Drawing. Color.

Just copy the class to MyColorPalette or whatever and
add the missing "Entries" setter, if that is what you are
looking for.

Do you just want the conversion functions or do you
actually need to assign an actual
System.Drawing. Imaging.ColorPa lette object to something?

Regards,

Joergen Bech

On Sat, 14 Jul 2007 13:49:13 -0400, " active"
<ac********** @a-znet.comwrote:
>The ColorPalette class has no constructor so how does one use it?
I define a variable by:

Dim cp as ColorPalette

but don't know how assign an object to the variable.

Thanks in advance


Jul 14 '07 #6
For each entry:
get an entry from a Bitmap color table
modify it
store the modified entry in a color table
Assign the new color table to the bitmap.

So I think I can do what the other posters suggested.

But I would like to know what you meant by the following.
Just copy the class to MyColorPalette

Thanks
Jul 14 '07 #7

My suggestion was that if you needed a class
with the same behavior as ColorPalette, but with
a few changes, you could just copy the code from
the ColorPalette class to another class with the
name and additional functionality of your choice.
There are various tools for decompiling the framework.

But if you need to assign a ColorPalette object
to a property that expects the type found in the
framework, this might not be an option.

As for assigning a palette from a dummy palette
indirectly created by creating a new bitmap of the
same bit depth: No can do.

MyBitmap.Palett e = <ColorPalette object>

is not the same as

MyBitmap.Palett e = <some other bitmap>.Palette .

In the latter case, you are going through some
GDI+ functions to get a new palette rather than
just getting a ColorPalette object directly.

When assigned to MyBitmap.Palett e, you are
jumping through similar hoops.

Try the code below. You will find that nothing
works as expected. All copies are identical to
the original. Attempts to change the colors in
any of these manners are ignored.

I use an imaging toolkit for similar needs, so I
haven't digged deeper into this. There might be
a solution. Then again, there might not. It is possible
that Microsoft has made it *possible* to change the
Palette.Entries values, but not *intended* for them
to be changed or react to such changes.

Please prove me wrong.

Regards,

Joergen Bech

---snip---

'Load image
Dim lena8 As New Bitmap("d:\lena 8.bmp")

'Save it again to verify that we read it correctly
lena8.Save("d:\ lena8-original.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Work with a palette created as a copy of the palette of the
original image
Dim cp As ColorPalette = lena8.Palette

For i As Integer = 0 To 255
cp.Entries(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = cp
lena8.Save("d:\ lena8-cp.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Work with a dummy palette created by creating another bitmap
Dim bm As New Bitmap(1, 1, PixelFormat.For mat8bppIndexed)
For i As Integer = 0 To 255
bm.Palette.Entr ies(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = bm.Palette
lena8.Save("d:\ lena8-bm.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Modify palette entries directly in the original image
For i As Integer = 0 To 255
lena8.Palette.E ntries(i) = Color.FromArgb( i, i, i)
Next
lena8.Save("d:\ lena8-0-255.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

---snip---

On Sat, 14 Jul 2007 17:31:09 -0400, " active"
<ac********** @a-znet.comwrote:
>For each entry:
get an entry from a Bitmap color table
modify it
store the modified entry in a color table
Assign the new color table to the bitmap.

So I think I can do what the other posters suggested.

But I would like to know what you meant by the following.
>Just copy the class to MyColorPalette


Thanks
Jul 14 '07 #8
Never decompiled the framework so it didn't occur to me that was what you
meant.

Thanks for taking so much time to answer so completely.

I need to study the code.

thanks

"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNO SPAMwrote in message
news:5n******** *************** *********@4ax.c om...
>
My suggestion was that if you needed a class
with the same behavior as ColorPalette, but with
a few changes, you could just copy the code from
the ColorPalette class to another class with the
name and additional functionality of your choice.
There are various tools for decompiling the framework.

But if you need to assign a ColorPalette object
to a property that expects the type found in the
framework, this might not be an option.

As for assigning a palette from a dummy palette
indirectly created by creating a new bitmap of the
same bit depth: No can do.

MyBitmap.Palett e = <ColorPalette object>

is not the same as

MyBitmap.Palett e = <some other bitmap>.Palette .

In the latter case, you are going through some
GDI+ functions to get a new palette rather than
just getting a ColorPalette object directly.

When assigned to MyBitmap.Palett e, you are
jumping through similar hoops.

Try the code below. You will find that nothing
works as expected. All copies are identical to
the original. Attempts to change the colors in
any of these manners are ignored.

I use an imaging toolkit for similar needs, so I
haven't digged deeper into this. There might be
a solution. Then again, there might not. It is possible
that Microsoft has made it *possible* to change the
Palette.Entries values, but not *intended* for them
to be changed or react to such changes.

Please prove me wrong.

Regards,

Joergen Bech

---snip---

'Load image
Dim lena8 As New Bitmap("d:\lena 8.bmp")

'Save it again to verify that we read it correctly
lena8.Save("d:\ lena8-original.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Work with a palette created as a copy of the palette of the
original image
Dim cp As ColorPalette = lena8.Palette

For i As Integer = 0 To 255
cp.Entries(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = cp
lena8.Save("d:\ lena8-cp.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Work with a dummy palette created by creating another bitmap
Dim bm As New Bitmap(1, 1, PixelFormat.For mat8bppIndexed)
For i As Integer = 0 To 255
bm.Palette.Entr ies(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = bm.Palette
lena8.Save("d:\ lena8-bm.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Modify palette entries directly in the original image
For i As Integer = 0 To 255
lena8.Palette.E ntries(i) = Color.FromArgb( i, i, i)
Next
lena8.Save("d:\ lena8-0-255.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

---snip---

On Sat, 14 Jul 2007 17:31:09 -0400, " active"
<ac********** @a-znet.comwrote:
>>For each entry:
get an entry from a Bitmap color table
modify it
store the modified entry in a color table
Assign the new color table to the bitmap.

So I think I can do what the other posters suggested.

But I would like to know what you meant by the following.
>>Just copy the class to MyColorPalette


Thanks

Jul 14 '07 #9
What was MS thinking?
Why not make Entries readonly?
I add a statement to yout code:
The line written did not reflect i,i,i

lena8.Palette.E ntries(i) = Color.FromArgb( i, i, i)

Console.WriteLi ne("Entry({0} = {1}", i, lena8.Palette.E ntries(i))


"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNO SPAMwrote in message
news:5n******** *************** *********@4ax.c om...
>
My suggestion was that if you needed a class
with the same behavior as ColorPalette, but with
a few changes, you could just copy the code from
the ColorPalette class to another class with the
name and additional functionality of your choice.
There are various tools for decompiling the framework.

But if you need to assign a ColorPalette object
to a property that expects the type found in the
framework, this might not be an option.

As for assigning a palette from a dummy palette
indirectly created by creating a new bitmap of the
same bit depth: No can do.

MyBitmap.Palett e = <ColorPalette object>

is not the same as

MyBitmap.Palett e = <some other bitmap>.Palette .

In the latter case, you are going through some
GDI+ functions to get a new palette rather than
just getting a ColorPalette object directly.

When assigned to MyBitmap.Palett e, you are
jumping through similar hoops.

Try the code below. You will find that nothing
works as expected. All copies are identical to
the original. Attempts to change the colors in
any of these manners are ignored.

I use an imaging toolkit for similar needs, so I
haven't digged deeper into this. There might be
a solution. Then again, there might not. It is possible
that Microsoft has made it *possible* to change the
Palette.Entries values, but not *intended* for them
to be changed or react to such changes.

Please prove me wrong.

Regards,

Joergen Bech

---snip---

'Load image
Dim lena8 As New Bitmap("d:\lena 8.bmp")

'Save it again to verify that we read it correctly
lena8.Save("d:\ lena8-original.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Work with a palette created as a copy of the palette of the
original image
Dim cp As ColorPalette = lena8.Palette

For i As Integer = 0 To 255
cp.Entries(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = cp
lena8.Save("d:\ lena8-cp.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Work with a dummy palette created by creating another bitmap
Dim bm As New Bitmap(1, 1, PixelFormat.For mat8bppIndexed)
For i As Integer = 0 To 255
bm.Palette.Entr ies(i) = Color.FromArgb( i, i, i)
Next
lena8.Palette = bm.Palette
lena8.Save("d:\ lena8-bm.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

'Modify palette entries directly in the original image
For i As Integer = 0 To 255
lena8.Palette.E ntries(i) = Color.FromArgb( i, i, i)
Next
lena8.Save("d:\ lena8-0-255.bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

---snip---

On Sat, 14 Jul 2007 17:31:09 -0400, " active"
<ac********** @a-znet.comwrote:
>>For each entry:
get an entry from a Bitmap color table
modify it
store the modified entry in a color table
Assign the new color table to the bitmap.

So I think I can do what the other posters suggested.

But I would like to know what you meant by the following.
>>Just copy the class to MyColorPalette


Thanks

Jul 15 '07 #10

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

Similar topics

50
6321
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the...
13
2360
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes. Two sub-classes have the relationship to communicate back and forth through this pointer. The pointer is responsible inside Top class for allocating...
23
5158
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
3
1671
by: G. Purby | last post by:
What is the proper way of defining a class that inherits from a base class that has no constructor with 0 arguments? The following code generates compiler error CS1501, "No overload for method 'BaseClass' takes '0' arguments". class BaseClass { public BaseClass(double x) {
10
4679
by: Joel | last post by:
Is it true that if we don't specify a default constructor for our class, then the C# compiler provides us with its own that zeroes (or assigns default values) to the data members? I wrote a no-parameter constructor for my class with an empty function body. I then instantiated an object and tried printing its values, amazingly the members...
10
11402
by: Nathan Sokalski | last post by:
How do I create a new System.Drawing.Imaging.ColorPalette? ColorPalette does not have a constructor, and the Entries property is ReadOnly. How are we supposed to specify a palette other than the default? If there were a method to import an Array or Collection of System.Drawing.Color or something, it would be no problem, but the way it is set...
0
7804
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...
0
8156
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. ...
1
7910
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...
0
8180
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...
1
5681
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...
0
5366
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...
0
3809
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...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
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

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.