Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Due to the fact, that the <a href="http://msdn.microsoft.com/en-us/library/14w97wkc.aspx"><code>Color</code></a> structure already has a <a href="http://msdn.microsoft.com/en-us/library/system.drawing.color.gethue.aspx"><code>GetHue()</code></a>, <a href="http://msdn.microsoft.com/en-us/library/system.drawing.color.getsaturation.aspx"><code>GetSaturation()</code></a> and <a href="http://msdn.microsoft.com/en-us/library/system.drawing.color.getbrightness.aspx"><code>GetBrightness()</code></a> it would be nice to also construct a color from these values. So i found the following code somewhere on the net a while ago (currently can't find it again, but it was from a Microsoft guy blog and he also had a test that steps through all <a href="http://msdn.microsoft.com/en-us/library/system.drawing.knowncolor.aspx"><code>KnownColor</code></a>).</p> <pre><code>/// &lt;summary&gt; /// Creates a Color from alpha, hue, saturation and brightness. /// &lt;/summary&gt; /// &lt;param name="alpha"&gt;The alpha channel value.&lt;/param&gt; /// &lt;param name="hue"&gt;The hue value.&lt;/param&gt; /// &lt;param name="saturation"&gt;The saturation value.&lt;/param&gt; /// &lt;param name="brightness"&gt;The brightness value.&lt;/param&gt; /// &lt;returns&gt;A Color with the given values.&lt;/returns&gt; public static Color FromAhsb(int alpha, float hue, float saturation, float brightness) { if (0 &gt; alpha || 255 &lt; alpha) { throw new ArgumentOutOfRangeException("alpha", alpha, "Value must be within a range of 0 - 255."); } if (0f &gt; hue || 360f &lt; hue) { throw new ArgumentOutOfRangeException("hue", hue, "Value must be within a range of 0 - 360."); } if (0f &gt; saturation || 1f &lt; saturation) { throw new ArgumentOutOfRangeException("saturation", saturation, "Value must be within a range of 0 - 1."); } if (0f &gt; brightness || 1f &lt; brightness) { throw new ArgumentOutOfRangeException("brightness", brightness, "Value must be within a range of 0 - 1."); } if (0 == saturation) { return Color.FromArgb(alpha, Convert.ToInt32(brightness * 255), Convert.ToInt32(brightness * 255), Convert.ToInt32(brightness * 255)); } float fMax, fMid, fMin; int iSextant, iMax, iMid, iMin; if (0.5 &lt; brightness) { fMax = brightness - (brightness * saturation) + saturation; fMin = brightness + (brightness * saturation) - saturation; } else { fMax = brightness + (brightness * saturation); fMin = brightness - (brightness * saturation); } iSextant = (int)Math.Floor(hue / 60f); if (300f &lt;= hue) { hue -= 360f; } hue /= 60f; hue -= 2f * (float)Math.Floor(((iSextant + 1f) % 6f) / 2f); if (0 == iSextant % 2) { fMid = hue * (fMax - fMin) + fMin; } else { fMid = fMin - hue * (fMax - fMin); } iMax = Convert.ToInt32(fMax * 255); iMid = Convert.ToInt32(fMid * 255); iMin = Convert.ToInt32(fMin * 255); switch (iSextant) { case 1: return Color.FromArgb(alpha, iMid, iMax, iMin); case 2: return Color.FromArgb(alpha, iMin, iMax, iMid); case 3: return Color.FromArgb(alpha, iMin, iMid, iMax); case 4: return Color.FromArgb(alpha, iMid, iMin, iMax); case 5: return Color.FromArgb(alpha, iMax, iMin, iMid); default: return Color.FromArgb(alpha, iMax, iMid, iMin); } } </code></pre> <p>With this function you are able to work within the HSB (or HSV) color presentation <strong>not</strong> within the HSL presentation. For further informations about their differences take a look at <a href="http://en.wikipedia.org/wiki/HSV_color_space">this wikipedia article</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload