RomanK Posted January 23, 2009 Posted January 23, 2009 (edited) Hi guys,just a quick question...Let's say I have the hex color 0xFFC90F which is something between yellow and orange.I have a gui with that background color and a label on top of it.The label needs to clearly readable. So you might suggest to make its font black.Well, but the background color can be changed. The font will be invisible or hardly to read when the background is black or grey.How can I let autoit calculate a good font color depending on the GUI background?RomanEDIT: Sorry for posting in the wrong section. Please move it, thanks! Edited January 23, 2009 by RomanK [font="Courier New"]http://RomanK.hondadesigns.com[/font]
KaFu Posted January 23, 2009 Posted January 23, 2009 Can't remember where I found this piece of code, kudos to the author ... #Include <Color.au3> MsgBox(0,'',_ColorInverse('0xFFC90F')) Func _ColorInverse($nColor) Local $nRed = _ColorGetRed($nColor) Local $nGreen = _ColorGetGreen($nColor) Local $nBlue = _ColorGetBlue($nColor) Return "0x" & Hex(255 - $nRed, 2) & Hex(255 - $nGreen, 2) & Hex(255 - $nBlue, 2) EndFunc ;==>_ColorInverse OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
ProgAndy Posted January 23, 2009 Posted January 23, 2009 This should get better readable colors: Func _CalcContrastColor ($crBg) ; http://www.codeproject.com/KB/tips/JbColorContrast.aspx Local Const $TOLERANCE = 30 if ( _ abs(BitAND($crBg , 0xFF) - 0x80) <= $TOLERANCE And _ abs(BitAND(BitShift($crBg , 8) , 0xFF) - 0x80) <= $TOLERANCE And _ abs(BitAND(BitShift($crBg , 16) & 0xFF) - 0x80) <= $TOLERANCE _ ) Then return BitAND((0x7F7F7F + $crBg) , 0xFFFFFF); return BitXOR($crBg ,0xFFFFFF); EndFunc (opposite color is not a good choice for our eyes) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
KaFu Posted January 23, 2009 Posted January 23, 2009 (opposite color is not a good choice for our eyes)Nice , yeah, I found it commented out in one of my scripts ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
RomanK Posted January 23, 2009 Author Posted January 23, 2009 Thanks to both of you. @ProgAndy: This gives nice colors, may I use it for Caravelle³ ? [font="Courier New"]http://RomanK.hondadesigns.com[/font]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now