Jump to content

[SOLVED] Hex ARGB Make color lighter or darker


algiuxas
 Share

Recommended Posts

Hello,

I'm working on small game, I need to change hex color(0xAARRGGBB), change transparency, red, green or blue color.

Could somebody help me, and write example maybe?

Thanks :)

Edited by algiuxas

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

Here we go:

$iColor_Current = 0xFFAABBCC

;extract the channels
$iAlpha = BitAND(BitShift($iColor_Current, 24), 0xFF)
$iRed = BitAND(BitShift($iColor_Current, 16), 0xFF)
$iGreen = BitAND(BitShift($iColor_Current, 8), 0xFF)
$iBlue = BitAND($iColor_Current, 0xFF)

;half the color values
$iAlpha_new = Int($iAlpha / 2)
$iRed_new = Int($iRed / 2)
$iGreen_new = Int($iGreen / 2)
$iBlue_new = Int($iBlue / 2)

;merge new values to a color 32-bit value again
$iColor_new = 0x1000000 * $iAlpha_new + 0x10000 * $iRed_new + 0x100 * $iGreen_new + $iBlue_new

MsgBox(0, "Test",   "Old: " & @TAB & Hex($iColor_Current, 8) & @CRLF & _
                    "New: " & @TAB & Hex($iColor_new, 8))

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

53 minutes ago, UEZ said:

Here we go:

$iColor_Current = 0xFFAABBCC

;extract the channels
$iAlpha = BitAND(BitShift($iColor_Current, 24), 0xFF)
$iRed = BitAND(BitShift($iColor_Current, 16), 0xFF)
$iGreen = BitAND(BitShift($iColor_Current, 8), 0xFF)
$iBlue = BitAND($iColor_Current, 0xFF)

;half the color values
$iAlpha_new = Int($iAlpha / 2)
$iRed_new = Int($iRed / 2)
$iGreen_new = Int($iGreen / 2)
$iBlue_new = Int($iBlue / 2)

;merge new values to a color 32-bit value again
$iColor_new = 0x1000000 * $iAlpha_new + 0x10000 * $iRed_new + 0x100 * $iGreen_new + $iBlue_new

MsgBox(0, "Test",   "Old: " & @TAB & Hex($iColor_Current, 8) & @CRLF & _
                    "New: " & @TAB & Hex($iColor_new, 8))

 

Thank You very much!!

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...