« 8bitカラー値をhex値に変換 | トップページ | Pantone Color Swatch »

[8BIT2HEX]8bitカラー値をhex値に変換

8bitカラー値をhex値に変換
record--> NSDictionaryから値を参照する方式(現時点で一番速い
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-c6e523.html

【スクリプトエディタで開く】|

set strRno to "0"
set strGno to "128"
set strBno to "255"

# printfを使う
set strCommandText to ("/usr/bin/printf \"%02X\" \"" & strRno & "\"") as text
set strRhex to (do shell script strCommandText)
set strCommandText to ("/usr/bin/printf \"%02X\" \"" & strGno & "\"") as text
set strGhex to (do shell script strCommandText)
set strCommandText to ("/usr/bin/printf \"%02X\" \"" & strBno & "\"") as text
set strBhex to (do shell script strCommandText)
set strColorHex to (strRhex & strGhex & strBhex) as text
-->"0080FF"

# printfを使う
set strCommandText to ("/usr/bin/printf \"%02X%02X%02X\" `/bin/echo \"" & strRno & " " & strGno & " " & strBno & "\"`") as text
set strBhex to (do shell script strCommandText)
--> "0080FF"

# perlを使う
set strCommandText to ("/usr/bin/perl -e 'printf(\"%02X\"," & strRno & ")'") as text
set strRhex to (do shell script strCommandText) as text
set strCommandText to ("/usr/bin/perl -e 'printf(\"%02X\"," & strGno & ")'") as text
set strGhex to (do shell script strCommandText) as text
set strCommandText to ("/usr/bin/perl -e 'printf(\"%02X\"," & strBno & ")'") as text
set strBhex to (do shell script strCommandText) as text
set strColorHex to (strRhex & strGhex & strBhex) as text
-->"0080FF"

# python3を使う
set strRGB8Bit to (strRno & strGno & strBno) as text
set strCommandText to ("/usr/bin/python3 -c \"print('%02X%02X%02X' % (" & strRno & "," & strGno & "," & strBno & "))\"") as text
set strRGBHEX to (do shell script strCommandText) as text
-->"0080FF"

|

« 8bitカラー値をhex値に変換 | トップページ | Pantone Color Swatch »

AppleScript Color」カテゴリの記事