Creating a System.Drawing.Imaging.ColorPalette

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Creating a System.Drawing.Imaging.ColorPalette

    How do I create a new System.Drawing. Imaging.ColorPa lette? 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
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Peter Duniho

    #2
    Re: Creating a System.Drawing. Imaging.ColorPa lette

    (m.p.dotnet.lan guages.vb deleted from Newsgroups:)

    On Sat, 01 Nov 2008 19:52:03 -0700, Nathan Sokalski
    <njsokalski@hot mail.comwrote:
    How do I create a new System.Drawing. Imaging.ColorPa lette? 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

    Comment

    • James Hahn

      #3
      Re: Creating a System.Drawing. Imaging.ColorPa lette

      What do you need to do with a palette that you can't do with
      System.Drawing. Imaging.ImageAt tributes?

      "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
      news:OQ1y8XJPJH A.3528@TK2MSFTN GP04.phx.gbl...
      How do I create a new System.Drawing. Imaging.ColorPa lette? 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
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

      >

      Comment

      • Peter Duniho

        #4
        Re: Creating a System.Drawing. Imaging.ColorPa lette

        (m.p.dotnet.lan guages.vb removed from Newsgroup:)

        On Sat, 01 Nov 2008 23:57:34 -0700, James Hahn <jhahn@yahoo.co mwrote:
        What do you need to do with a palette that you can't do with
        System.Drawing. Imaging.ImageAt tributes?
        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

        Comment

        • Family Tree Mike

          #5
          Re: Creating a System.Drawing. Imaging.ColorPa lette

          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" <NpOeStPeAdM@nn owslpianmk.comw rote in message
          news:op.ujzfalz r8jd0ej@petes-computer.local. ..
          (m.p.dotnet.lan guages.vb removed from Newsgroup:)
          >
          Pete

          Comment

          • Peter Duniho

            #6
            Re: Creating a System.Drawing. Imaging.ColorPa lette

            On Sun, 02 Nov 2008 05:41:26 -0700, Family Tree Mike
            <FamilyTreeMike @thisoldhouse.c omwrote:
            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

            Comment

            • Family Tree Mike

              #7
              Re: Creating a System.Drawing. Imaging.ColorPa lette

              That makes sense, and thanks for clarifying. I think the VB.Net crowd needs
              your wisdom too.

              Mike

              "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
              news:op.ujz8qzb d8jd0ej@petes-computer.local. ..
              On Sun, 02 Nov 2008 05:41:26 -0700, Family Tree Mike
              <FamilyTreeMike @thisoldhouse.c omwrote:
              >
              >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

              Comment

              • raylopez99

                #8
                Re: Creating a System.Drawing. Imaging.ColorPa lette

                BTW, microsoft.publi c.dotnet.framew ork.drawing

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

                RL

                Comment

                • Jeff Johnson

                  #9
                  Re: Creating a System.Drawing. Imaging.ColorPa lette

                  "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
                  news:op.ujz8qzb d8jd0ej@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.


                  Comment

                  • Peter Duniho

                    #10
                    Re: Creating a System.Drawing. Imaging.ColorPa lette

                    On Mon, 03 Nov 2008 14:00:43 -0800, Jeff Johnson <i.get@enough.s pamwrote:
                    "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
                    news:op.ujz8qzb d8jd0ej@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

                    Comment

                    • Bob Powell [MVP]

                      #11
                      Re: Creating a System.Drawing. Imaging.ColorPa lette

                      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


                      Find great Windows Forms articles in Windows Forms Tips and Tricks


                      Answer those GDI+ questions with the GDI+ FAQ


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

                      "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
                      news:OQ1y8XJPJH A.3528@TK2MSFTN GP04.phx.gbl...
                      How do I create a new System.Drawing. Imaging.ColorPa lette? 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
                      njsokalski@hotm ail.com
                      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

                      >

                      Comment

                      Working...