How to check if two System.Drawing.Color structures represent the same color in 16 bit color depth?

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-02-02T14:18:01Z Indexed on 2010/04/17 22:53 UTC
Read the original article Hit count: 364

How can I check if two System.Drawing.Color structures represent the same color in 16 bit color depth (or generally based on the value of Screen.PrimaryScreen.BitsPerPixel)?

Let's say I set Form.TransparencyKey to Value1 (of Color type), I want to check that when the user selects a new background color for the form (Value2), I don't set the entire form transparent.

On 32bit color depth screens I simply compare the two values:

if (Value1 == Value2)

However, this does not work on 16bit color depth screens, as more Color values for the Value2 would represent the same actual 16bit color as Value1, as I found out the hard way.

© Stack Overflow or respective owner

Related posts about c#

Related posts about color