Home All Groups Group Topic Archive Search About

How can I calculate GetBrightness ny myself?

Author
17 Oct 2006 4:14 PM
Dominic
I know there is a function named GetBrightness() on .net framework but if I
need to write this function by myself, how can I do?

Because some language does not provide this function, can I calculate by
using R G B of the color?

Thanks

Author
18 Oct 2006 2:14 AM
Chris
Hi Dominic,

Using Lutz Roeder's Reflector, I see the following code under
System.Drawing.Color:

''' <summary>Gets the hue-saturation-brightness (HSB) brightness value for
this <see cref="T:System.Drawing.Color"></see> structure.</summary>
''' <returns>The brightness of this <see
cref="T:System.Drawing.Color"></see>. The brightness ranges from 0.0 through
1.0, where 0.0 represents black and 1.0 represents white.</returns>
Public Function GetBrightness() As Single
      Dim single1 As Single = (CSng(Me.R) / 255!)
      Dim single2 As Single = (CSng(Me.G) / 255!)
      Dim single3 As Single = (CSng(Me.B) / 255!)
      Dim single4 As Single = single1
      Dim single5 As Single = single1
      If (single2 > single4) Then
            single4 = single2
      End If
      If (single3 > single4) Then
            single4 = single3
      End If
      If (single2 < single5) Then
            single5 = single2
      End If
      If (single3 < single5) Then
            single5 = single3
      End If
      Return ((single4 + single5) / 2!)
End Function


MSDN article for more info:
http://msdn2.microsoft.com/en-us/library/system.drawing.color.getbrightness.aspx

Hope this information helps,

Chris

Show quoteHide quote
"Dominic" <j_ala***@hotmail.com> wrote in message
news:eK6yddg8GHA.3396@TK2MSFTNGP04.phx.gbl...
>I know there is a function named GetBrightness() on .net framework but if I
>need to write this function by myself, how can I do?
>
> Because some language does not provide this function, can I calculate by
> using R G B of the color?
>
> Thanks
>