TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: C# Color Space Converter

17 pointsby nobody271over 6 years ago

5 comments

Taniwhaover 6 years ago
In the past I used to build this stuff in silicon .... just a quick note it's quite common in the real world to get incoming values that are out of gamut (the results of compressing and decompressing data for example) - you need to pin your final values to 0-255 in the cases where they are < 0 or > 255 otherwise they tend to wrap, you also need to carry that extra bit of precision through your math (not such an issue with FP) to make sure you can detect this
评论 #18522847 未加载
nobody271over 6 years ago
This is mostly a port of the code on <a href="https:&#x2F;&#x2F;www.easyrgb.com&#x2F;en&#x2F;math.php" rel="nofollow">https:&#x2F;&#x2F;www.easyrgb.com&#x2F;en&#x2F;math.php</a> but I have added a few extras.<p>What I use it for is:<p>* RGB - easy to guess what values to use to make a color<p>* HSL - easy to change the hue of a color<p>* Lab - lets you compare colors<p>* Named color - lets you know the name of a color
评论 #18519620 未加载
Meph504over 6 years ago
The builtin System.Drawing.Color namespace already contains much of what you have in regards to colors to and from names.<p>There are a lot of helpful methods available.<p>Color foo = Color.FromArgb(int); int foo = Color.ToArgb(); Color foo = Color.FromName(&quot;CornflowerBlue&quot;);<p>Color itself also exposes .IsKnownColor and .IsNamedColor
评论 #18519670 未加载
Systemic33over 6 years ago
Lab has the cool effect that you can smoothly change the luminance of a particular color in steps (usually scale is 0-100), where each step has an equal perception of change to the user.<p>Very useful when making gradients.<p>I used this for my MSc thesis project :)
danbrucover 6 years ago
For more advanced needs there is Colourful .NET [1].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tompazourek&#x2F;Colourful" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tompazourek&#x2F;Colourful</a>
评论 #18519496 未加载