示例代码:
GraphicsWindow.MouseDown = md
Sub md
color = GraphicsWindow.GetPixel(GraphicsWindow.MouseX,GraphicsWindow.MouseY)
EndSub这将返回一个十六进制值,但我需要将其转换为RGB值。我该怎么做呢?
发布于 2017-05-31 03:45:25
转换的诀窍是处理那些讨厌的字母。我发现最简单的方法是使用"Map“结构,将十六进制数字等同于十进制值。Small Basic使得这变得非常简单,因为Small Basic中的数组实际上是作为map实现的。
我根据你上面的代码片段做了一个完整的例子。您可以使用下面这个小的基本导入代码来获得它: CJK283
下面的子例程是重要的部分。它将两位十六进制数转换为十进制等效数。它还强调了Small Basic中有限的子例程。在Small Basic中,这需要在子例程中使用变量,并且至少需要三行代码才能调用子例程,而不是像在其他语言中看到的那样,每次调用都使用一行代码。
'Call to the ConvertToHex Subroutine
hex = Text.GetSubText(color,2,2)
DecimalFromHex()
red = decimal
Convert a Hex string to Decimal
Sub DecimalFromHex
'Set an array as a quick and dirty way of converting a hex value into a decimal value
hexValues = "0=0;1=1;2=2;3=3;4=4;5=5;6=6;7=7;8=8;9=9;A=10;B=11;C=12;D=13;E=14;F=15"
hiNibble = Text.GetSubText(hex,1,1) 'The high order nibble of this byte
loNibble = Text.GetSubText(hex,2,1) 'The low order nibble of this byte
hiVal = hexValues[hiNibble] * 16 'Combine the nibbles into a decimal value
loVal = hexValues[loNibble]
decimal = hiVal + loVal
EndSubhttps://stackoverflow.com/questions/44210750
复制相似问题