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. Find Reverse Color

Find Reverse Color

Scheduled Pinned Locked Moved C#
questiontutorial
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.
  • W Offline
    W Offline
    Werdna
    wrote on last edited by
    #1

    How can I find a reverse of a color? Actually what I need is a color that will be readable on another background color. For example if the background is white, the color would be black, if the background is dark green, the color would be white. I tried using GetBrightness() of color to determine whether to use white or black, but that doesn't seem to work.

    L 1 Reply Last reply
    0
    • W Werdna

      How can I find a reverse of a color? Actually what I need is a color that will be readable on another background color. For example if the background is white, the color would be black, if the background is dark green, the color would be white. I tried using GetBrightness() of color to determine whether to use white or black, but that doesn't seem to work.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      I recall reading a trick that mite work (not sure if it on works for 8 bit colors), but i forgot now :doh: (has to do with an XOR with -1 or just using the complement of an int, a color is just an int). But be inventive, try this:

      A2 = 256 - A1;//now this would be dumb
      R2 = 255 - R1;
      G2 = 255 - G1;
      B2 = 255 - B1;

      Mite work, let me know, im interested in what works :) [edit] this works pretty good [edit] top secret

      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