diff --git a/Base/GraphicsEx.vb b/Base/GraphicsEx.vb index d4c840b4..d75d1fa6 100644 --- a/Base/GraphicsEx.vb +++ b/Base/GraphicsEx.vb @@ -2,10 +2,20 @@ Public Class GraphicsEx - Public Shared Function GetBrightness(c As Color) As Single - Return (c.R * 0.299F + c.G * 0.587F + c.B * 0.114F) / 256.0F + ''' + ''' Returns the brightness of a color as a number between 0 and 1 + ''' + ''' The color to check + ''' Low values for dark colors, high values for bright colors. + Public Shared Function GetBrightness(pColor As Color) As Single + Return (pColor.R * 0.299F + pColor.G * 0.587F + pColor.B * 0.114F) / 256.0F End Function + ''' + ''' Returns a foreground/text color of either black or white, depending on the brightness of `pOtherColor` + ''' + ''' The Background color whose brightness is determined + ''' A text color which is either white or black Public Shared Function GetContrastedColor(pOtherColor As Color) As Color If GetBrightness(pOtherColor) < 0.55 Then Return Color.White @@ -13,4 +23,21 @@ Public Class GraphicsEx Return Color.Black End If End Function + + Public Sub DrawRectangle(Bounds As Rectangle) + Dim oContext As IntPtr + oContext = NativeMethods.GetDC(IntPtr.Zero) + + Try + Dim g As Graphics + g = Graphics.FromHdc(oContext) + Try + g.DrawRectangle(Pens.Red, Bounds) + Finally + g.Dispose() + End Try + Finally + NativeMethods.ReleaseDC(IntPtr.Zero, oContext) + End Try + End Sub End Class diff --git a/Base/StringEx.vb b/Base/StringEx.vb index 3aaeb2fd..2ae2a1b4 100644 --- a/Base/StringEx.vb +++ b/Base/StringEx.vb @@ -107,6 +107,10 @@ Public Class StringEx Return GetChecksum(pStringToCheck) End Function + Public Shared Function GetShortHash(pStringToCheck As String) As String + Return GetChecksum(pStringToCheck).Substring(0, 32) + End Function + Friend Class InvalidChars Public Shared Filenames As String = Regex.Escape(New String(IO.Path.GetInvalidFileNameChars())) Public Shared Paths As String = Regex.Escape(New String(IO.Path.GetInvalidPathChars()))