我正在开展一个项目,我必须从互联网网站,徽标等中获取颜色。
有什么办法可以获得我指向的颜色的RGB值吗?或者有什么方法可以将其中的彩色对象的RGB值作为文本获取,所以我也可以将其同样地提供给其他对象?
答案 0 :(得分:0)
您需要调用WinAPI函数来执行此操作。
我简化了它/改编它。它会将当前所选形状的颜色设置为光标下像素的颜色:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
'
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, _
ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) _
As Long
Sub Test()
Dim tPOS As POINTAPI
Dim sTmp As String
Dim lColor As Long
Dim lDC As Long
lDC = GetWindowDC(0)
Call GetCursorPos(tPOS)
lColor = GetPixel(lDC, tPOS.x, tPOS.y)
sTmp = Right$("000000" & Hex(lColor), 6)
ActiveWindow.Selection.ShapeRange(1).Fill.ForeColor.RGB = lColor
End Sub