VB进行RGB分色

Option Explicit

Private Type RGBA
    R As Byte
    G As Byte
    B As Byte
    A As Byte
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long) As RGBA 

Private Sub Command1_Click()
    Dim cor As RGBA
    '用GetPixel取色,直接就分出来,注意看GetPixel声明的返回类型
    cor = GetPixel(Me.hdc, 5, 5)
    Print cor.R, cor.G, cor.B
End Sub

Private Sub Command2_Click()
    Dim cor As RGBA
    Dim MeColor As Long
    MeColor = Me.BackColor
    '分离RGB
    CopyMemory cor, MeColor, 4
    Print cor.R, cor.G, cor.B
    '转回整形颜色值
    CopyMemory MeColor, cor, 4
    Print MeColor
End Sub

 

posted @ 2017-07-21 06:05  JustXIII  阅读(708)  评论(0编辑  收藏  举报