Is White/Black the best color for a specific BG color ?
Posted: Tue Apr 24, 2012 10:16 am
Code: Select all
Procedure GetTextColor(rgbRed.i,rgbGrn.i,rgbBlu.i)
Caption.s = "INFO"
Message.s = "H: #" + RSet(Hex(rgbRed),2,"0") + RSet(Hex(rgbGrn),2,"0") + RSet(Hex(rgbBlu),2,"0") + Chr(10)
Message.s + "D: RGB(" + Str(rgbRed) + "," + Str(rgbGrn) + "," + Str(rgbBlu) + ")" + Chr(10)
brightness.f = Sqr( (0.299 * Pow(rgbRed,2)) + (0.587 * Pow(rgbGrn,2)) + (0.114 * Pow(rgbBlu,2)) )
If brightness.f < 130
sOut.s = "#FFFFFF"
Else
sOut.s = "#000000"
EndIf
Message.s + "Text : " + sOut.s
MessageRequester(Caption.s,Message.s,80)
ProcedureReturn
EndProcedure
; Test Examples
GetTextColor(255,255,255)
GetTextColor(192,192,192)
GetTextColor(255,255,000)
GetTextColor(255,000,255)
GetTextColor(000,255,255)
GetTextColor(064,064,064)
GetTextColor(000,000,000)