473,785 Members | 2,129 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 2435
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
6382
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 method foo. But the initialization of attr2 is wrong
13
2388
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 and deallocating two sub-classes. CMemory class is responsible to allocate and deallocate memory...
23
5184
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
1676
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
4702
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 were already initialized. But how is this possible if I have not included any code for doing so. The...
10
11447
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 up right now I pretty much feel like it is useless. Any ideas? Thanks. -- Nathan Sokalski...
0
9646
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
9484
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
10157
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...
1
10097
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
9957
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
8983
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
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
3658
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.