Contrast & Opposite Colors

Nathan Sokalski 4,111 Reputation points
2022-07-19T23:12:41.597+00:00

I have found many articles & forum discussions on this, but I still haven't found a good simple solution. What I need to do is determine when I need a border on the shapes I am drawing. The shapes will always be solid opaque colors, and will be very basic (such as circles & squares). My goal is to hide the border when possible, but in order to make sure the shape is always visible, display it when the shape & background (which will always be #FF808080). What is the best way to determine when to display a border?

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,236 Reputation points Volunteer Moderator
    2022-07-20T01:32:08.717+00:00

    The solution is both simple and not simple.

    The standard approach is to calculate the border path. Then walk the border checking each pixel (or sample) to see it contrast is required. You may want a minimum length of path failure to determine if the border is required.

    This very similar to a fill, but checking just the border.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.