Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ColorPalette class

ColorPalette class

Scheduled Pinned Locked Moved C#
graphicsquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephane David
    wrote on last edited by
    #1

    How can it be used? The only thing I can do is retrieve the colors in the Entries. How can I change them? I'd like to change the palette of a 256 color gif. So I have Bitmap MyBitmap = new Bitmap("file.gif"); I tried MyBitmap.Palette.Entries[0] = Drawing.Color.Black, but it does nothing as Entries is a read only properties. How can I change the palette entries? Or how can I create a new ColorPalette? Bitmap.Palette is a read / write property, but there is no constructor for the ColorPalette class, and the ColorPalette.Entries are read only :confused:

    H 1 Reply Last reply
    0
    • S Stephane David

      How can it be used? The only thing I can do is retrieve the colors in the Entries. How can I change them? I'd like to change the palette of a 256 color gif. So I have Bitmap MyBitmap = new Bitmap("file.gif"); I tried MyBitmap.Palette.Entries[0] = Drawing.Color.Black, but it does nothing as Entries is a read only properties. How can I change the palette entries? Or how can I create a new ColorPalette? Bitmap.Palette is a read / write property, but there is no constructor for the ColorPalette class, and the ColorPalette.Entries are read only :confused:

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      ColorPalette is a value-type. You can change a value of it when it's a property of another type. For more information about value types vs. reference types, see http://www.albahari.com/value%20vs%20reference%20types.html[^]. In order to change the palette, you must first get a copy of the ColorPalette struct:

      ColorPalette palette = img.Palette;
      palette.Entries[0] = Color.Red;
      img.Palette = palette;

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups