您的位置:首页 > 编程语言 > VB

如何将一个包含颜色信息的长整类型转化为 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++ 代码的讨论。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  integer function vb
相关文章推荐