如何将一个包含颜色信息的长整类型转化为 RGB 表示

当我们用 GetPixel() 这样的函数来获取像素点信息时会返回一个长整数类型的值,若需要获得其以 RGB 形式的表示则需要进行转化,其在 VB 中转化的方法如下:
Public Function GetRValue(ByVal crColor As LongAs Integer
    
On Error GoTo ErrHandle
        
If crColor >= 0 Then
            GetRValue 
= crColor Mod 256
        
Else
            GetRValue 
= -1
        
End If
    
Exit Function
ErrHandle:
    GetRValue 
= -1
End Function


Public Function GetGValue(ByVal crColor As LongAs 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 Function


Public Function GetBValue(ByVal crColor As LongAs 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 Function
注:以上函数本质上为 RGB() 函数的反函数若调用时出现错误则返回-1,另外好像 C/C++ 中存在这样的转换函数在此不做 C/C++ 代码的讨论。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值