473,383 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Creating a System.Drawing.Imaging.ColorPalette

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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 2 '08 #1
10 11366
(m.p.dotnet.languages.vb deleted from Newsgroups:)

On Sat, 01 Nov 2008 19:52:03 -0700, Nathan Sokalski
<nj********@hotmail.comwrote:
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.
As the docs say, you are specifically restricted from creating a new color
palette. That is, it's by design that you can't (they say it's to make
sure you don't change the length of the palette). But, you can modify the
palette that's returned to you. The array property Entries is itself
read-only, but it's the actual array of palette entries, and the array
itself isn't read-only. So you can modify the entries of the palette
simply by setting them to a new color.

Once you've made all the changes to the palette you want, assign it back
to the Image. The palette used by the image will be updated accordingly.

Pete
Nov 2 '08 #2
What do you need to do with a palette that you can't do with
System.Drawing.Imaging.ImageAttributes?

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:OQ**************@TK2MSFTNGP04.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 2 '08 #3
(m.p.dotnet.languages.vb removed from Newsgroup:)

On Sat, 01 Nov 2008 23:57:34 -0700, James Hahn <jh***@yahoo.comwrote:
What do you need to do with a palette that you can't do with
System.Drawing.Imaging.ImageAttributes?
I can't speak for the OP. But the two are completely different things.
Modifying the palette is a change to the image itself. The
ImageAttributes class provides a way to filter the image during
_rendering_.

The latter would be inappropriate if you wanted to change the image in a
way that could then be saved to a file, or if you did not have direct
control over the rendering (i.e. had no way to change the code drawing the
image so that you could pass an instance of ImageAttributes when
drawing). Also, there is no way to use ImageAttributes to change colors
for specific indices. You can map colors, but if for some reason there
are two palette entries that start with the same color but which should be
changed to two different colors, ImageAttributes won't do that.

It's true that for certain tasks, they can be accomplished with either.
But the two are not in any way _equivalent_.

Pete
Nov 2 '08 #4
I'm currious why you dropped the .vb group. The question seems language
independent, and James seems to stick to the vb board, and may not see the
response.

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
(m.p.dotnet.languages.vb removed from Newsgroup:)

Pete
Nov 2 '08 #5
On Sun, 02 Nov 2008 05:41:26 -0700, Family Tree Mike
<Fa************@thisoldhouse.comwrote:
I'm currious why you dropped the .vb group. The question seems language
independent, and James seems to stick to the vb board, and may not see
the response.
Knee-jerk on my part. I was considering my reply in context to the
original post, and just assumed that James was posting from the ...drawing
newsgroup. I was using the same logic I used in my reply to the OP, even
though it didn't necessarily apply.

Oh well...that's a risk when people over-cross-post, whether they started
the thread or follow-up to it.

In any case, as for the general reason for deleting the VB.NET
newsgroup...my rule with respect to cross-posts is that when there are two
clearly contradictory newsgroups listed, one has to be deleted.

There is certainly some gray with respect to cross-posting in these .NET
newsgroup, where a newsgroup that's ostensibly language-specific (such as
the C# or VB.NET newsgroup) is used for questions not actually pertaining
to the language per se (such as asking about things in the Imaging or
Forms namespaces). I don't bother trying to argue against that sort of
cross-posting or misdirected posting (in the case where only the language
newsgroup is even used).

But, there is a _very_ clear contradiction between the C# and VB.NET
newsgroups. The only justification for posting non-language questions to
a language newsgroup is the marginal justification that the question is
being asked in the context of using that specific language. It is obvious
(to me) that only one language at a time can apply to questions like this,
and so any other language newsgroups need to be deleted.

I suppose I really ought to just ignore threads like that. I don't feel
comfortable propagating the bad cross-posting myself, and once the
cross-post has been done, you never know where the people other than the
OP are coming from (which is one of the problems with cross-posts,
especially overly broad ones).

Anyway, hope that clears things up, as much as might be possible.

Pete
Nov 2 '08 #6
That makes sense, and thanks for clarifying. I think the VB.Net crowd needs
your wisdom too.

Mike

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 02 Nov 2008 05:41:26 -0700, Family Tree Mike
<Fa************@thisoldhouse.comwrote:
>I'm currious why you dropped the .vb group. The question seems language
independent, and James seems to stick to the vb board, and may not see
the response.

Knee-jerk on my part. I was considering my reply in context to the
original post, and just assumed that James was posting from the ...drawing
newsgroup. I was using the same logic I used in my reply to the OP, even
though it didn't necessarily apply.

Oh well...that's a risk when people over-cross-post, whether they started
the thread or follow-up to it.

In any case, as for the general reason for deleting the VB.NET
newsgroup...my rule with respect to cross-posts is that when there are two
clearly contradictory newsgroups listed, one has to be deleted.

There is certainly some gray with respect to cross-posting in these .NET
newsgroup, where a newsgroup that's ostensibly language-specific (such as
the C# or VB.NET newsgroup) is used for questions not actually pertaining
to the language per se (such as asking about things in the Imaging or
Forms namespaces). I don't bother trying to argue against that sort of
cross-posting or misdirected posting (in the case where only the language
newsgroup is even used).

But, there is a _very_ clear contradiction between the C# and VB.NET
newsgroups. The only justification for posting non-language questions to
a language newsgroup is the marginal justification that the question is
being asked in the context of using that specific language. It is obvious
(to me) that only one language at a time can apply to questions like this,
and so any other language newsgroups need to be deleted.

I suppose I really ought to just ignore threads like that. I don't feel
comfortable propagating the bad cross-posting myself, and once the
cross-post has been done, you never know where the people other than the
OP are coming from (which is one of the problems with cross-posts,
especially overly broad ones).

Anyway, hope that clears things up, as much as might be possible.

Pete
Nov 2 '08 #7
BTW, microsoft.public.dotnet.framework.drawing

is a pretty dead board...but at least it's targeted for drawing so you
get a filter.

RL
Nov 3 '08 #8
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
In any case, as for the general reason for deleting the VB.NET
newsgroup...my rule with respect to cross-posts is that when there are two
clearly contradictory newsgroups listed, one has to be deleted.
Honestly, I think you should have removed BOTH language groups. As it
stands, it looks like you had a choice between VB and C# and said "screw
VB." No language was directly indicated in the original post (although words
like ReadOnly were a clue) so ultimately, if I were going to "teach the
poster a lesson," I'd remove everything but .drawing.
Nov 3 '08 #9
On Mon, 03 Nov 2008 14:00:43 -0800, Jeff Johnson <i.***@enough.spamwrote:
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
>In any case, as for the general reason for deleting the VB.NET
newsgroup...my rule with respect to cross-posts is that when there are
two
clearly contradictory newsgroups listed, one has to be deleted.

Honestly, I think you should have removed BOTH language groups. As it
stands, it looks like you had a choice between VB and C# and said "screw
VB."
That's not what I "said" at all. I simply personally feel that posting
the C# newsgroup and VB.NET newsgroup at the same time is an obvious
contradiction. You're ascribing to me motives I don't have.

As I said before, ideally only questions specific to the _language_ itself
(i.e. how to use some specific feature of the language) are actually
on-topic here. But, by community consensus, questions that are actually
about .NET generally are tolerated as well.

So while I don't disagree that technically the C# newsgroup is off-topic,
I don't feel strongly enough about it to try to instruct others to follow
that constraint, nor even enough to constrain myself in that way (indeed,
many of the answers I post here have nothing to do with C#).

Thus, out of three newsgroups, two are mutually exclusive, and so in
replying one of those two _had_ to be excluded, at least according to my
normal posting habits. Sometimes a habit causes one to do something
that's not entirely correct, but that's not really the point here I think.
No language was directly indicated in the original post (although words
like ReadOnly were a clue) so ultimately, if I were going to "teach the
poster a lesson," I'd remove everything but .drawing.
Well, if I were "going to teach the poster a lesson", perhaps I'd have
done that too. But teaching the OP a lesson wasn't my intent at all. My
removing the VB.NET newsgroup was simply part of my own desire to not be a
part of propagating a faulty posting pattern. Nothing more, nothing less.

YMMV.

Pete
Nov 4 '08 #10
The correct method is to create an 8 bit per pixel image and seal the
palette from it.

See my GIF articles on my site for some assistance.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:OQ**************@TK2MSFTNGP04.phx.gbl...
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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 12 '08 #11

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

Similar topics

7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
1
by: Ira | last post by:
I was successful in creating the multipage Tif files in VB.net using the following the following code: Public Sub SaveSeveralOnePageFilesInADir(ByVal DrNm As String, ByVal resultFl As String)...
4
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. ...
9
by: colin | last post by:
Hi, I have all the components of a .bmp file in memory wich i need to write to a .bmp file, (or other convenient image file) ie i have 256 color pallete of RGBquads and array of 8bit pixels, I...
2
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.