l = GetPixel(dd, p.x, p.y) 得到的颜色数值,如何转换成RGB呢?

stubird 2008-03-18 09:11:48
如题
Public Const p8_Color = 16243629
GetPixel(dd, p.x, p.y)得到的颜色数值类似与上面的那个
...全文
230 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Option Explicit

Private Sub Command1_Click()
Dim l As Long

l = RGB(0, 255, 0)

Dim r As Byte
Dim g As Byte
Dim b As Byte

getrgb l, r, g, b

End Sub

Private Sub getrgb(ByVal c As Long, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
If c < 0 Then
c = c + 2 ^ 32
End If

r = c Mod 256
g = (c \ 256) Mod 256
b = (c \ 65536) Mod 256

End Sub
回复
qiu5208 2008-03-19
学习。
回复
cbm6666 2008-03-18
窗体请装载一张图片

Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Dim Colorval&, Red&, Green&, Blue&
Private Sub Form_Load()
Me.ScaleMode = 3
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Colorval = GetPixel(Me.hDC, X, Y)
Call GetRGB(Colorval)
Me.Caption = CStr(Colorval) & " 分解为 红:" & CStr(Red) & " 绿:" & CStr(Green) & " 蓝:" & CStr(Blue)
End Sub

Public Sub GetRGB(Clrval As Long)
Red = Clrval Mod 256
Green = (Clrval \ 256) Mod 256
Blue = Clrval \ 256 \ 256
End Sub

回复
Option Explicit

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
ByVal Destination As Long, _
ByVal Source As Long, _
ByVal Length As Long)

Private Sub Command1_Click()
Dim I As Long, J(3) As Byte

I = 16243629
CopyMemory VarPtr(J(0)), VarPtr(I), 4
Debug.Print "R=" & Hex(J(0)) & " G=" & Hex(J(1)) & " B=" & Hex(J(2))
End Sub
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7490

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-18 09:11
社区公告
暂无公告