如何将一个包含颜色信息的长整类型转化为 RGB 表示
2006-10-06 21:01
393 查看
当我们用 GetPixel() 这样的函数来获取像素点信息时会返回一个长整数类型的值,若需要获得其以 RGB 形式的表示则需要进行转化,其在 VB 中转化的方法如下:
Public Function GetRValue(ByVal crColor As Long) As Integer
On Error GoTo ErrHandle
If crColor >= 0 Then
GetRValue = crColor Mod 256
Else
GetRValue = -1
End If
Exit Function
ErrHandle:
GetRValue = -1
End FunctionFunction GetRValue()
Public Function GetGValue(ByVal crColor As Long) As Integer
On Error GoTo ErrHandle
If crColor >= 0 Then
GetGValue = Fix((crColor / 256)) Mod 256
Else
GetGValue = -1
End If
Exit Function
ErrHandle:
GetGValue = -1
End FunctionFunction GetGValue()
Public Function GetBValue(ByVal crColor As Long) As Integer
On Error GoTo ErrHandle
If crColor >= 0 Then
GetBValue = Fix(crColor / 256 / 256)
Else
GetBValue = -1
End If
Exit Function
ErrHandle:
GetBValue = -1
End FunctionFunction GetBValue()
注:以上函数本质上为 RGB() 函数的反函数若调用时出现错误则返回-1,另外好像 C/C++ 中存在这样的转换函数在此不做 C/C++ 代码的讨论。
Public Function GetRValue(ByVal crColor As Long) As Integer
On Error GoTo ErrHandle
If crColor >= 0 Then
GetRValue = crColor Mod 256
Else
GetRValue = -1
End If
Exit Function
ErrHandle:
GetRValue = -1
End FunctionFunction GetRValue()
Public Function GetGValue(ByVal crColor As Long) As Integer
On Error GoTo ErrHandle
If crColor >= 0 Then
GetGValue = Fix((crColor / 256)) Mod 256
Else
GetGValue = -1
End If
Exit Function
ErrHandle:
GetGValue = -1
End FunctionFunction GetGValue()
Public Function GetBValue(ByVal crColor As Long) As Integer
On Error GoTo ErrHandle
If crColor >= 0 Then
GetBValue = Fix(crColor / 256 / 256)
Else
GetBValue = -1
End If
Exit Function
ErrHandle:
GetBValue = -1
End FunctionFunction GetBValue()
注:以上函数本质上为 RGB() 函数的反函数若调用时出现错误则返回-1,另外好像 C/C++ 中存在这样的转换函数在此不做 C/C++ 代码的讨论。
相关文章推荐
- 将一个正整数N用二进制表示并转化为一个string类型的值s
- 一个对象类型的数据如何转化为String类型
- How to import an oracle dump in an different tablespace ( 如何将一个包含表空间信息的dmp文件导入到另一个表空间)
- 数学老师小y想写一个成绩查询系统,包含如下指令:1.insert [name] [score],向系统中插入一条信息,表示名字为name的学生的数学成绩为score.2.find [name],表示查
- 16进制字符窜表示的颜色转化为RGB格式
- fastJson如何序列化一个包含list对象的Map对象,如Map<String,List<T>>类型的对象
- 如何计算 一个音视频文件 (.ts)文件 (包含pcr信息). 播放所使用的带宽
- 如何判断一个NVARCHAR类型的字段中包含中文(这里只为简体中文)
- 如何将一个String类型的数据转化为Map类型
- 在Linux上,如何知道一个可执行文件是否包含调试信息呢?
- 借助类型转化考察浮点数在内存中表示的一个心得
- 收录一个RGB颜色转化的库
- 实现一个view从顶部移到底部的动画 and 将RGB值转化为颜色
- 实现一个view从顶部移到底部的动画 and 将RGB值转化为颜色
- JS如何将数字类型转化为没3个一个逗号的金钱格式
- 借助类型转化考察浮点数在内存中表示的一个心得
- iOS 之如何将#737373颜色转化成RGB
- 如何获得桌面上任意一个位置的颜色的 rgb 或者16进制值了
- 如何计算 一个音视频文件 (.ts)文件 (包含pcr信息). 播放所使用的带宽
- 如何从EditText 获取信息(包含强制转换数据类型)