|
-
Mar 30th, 2004, 08:44 PM
#1
Thread Starter
Frenzied Member
How can you get the color at a certain point on the screen?
How can i specify a X and Y coordinate on the screen and determine what color is there?
-
Mar 31st, 2004, 10:26 AM
#2
Hyperactive Member
VB Code:
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Now, if you want the RGB values, use this function:
VB Code:
Sub obtainRGB(cValue, varRed, varGreen, varBlue)
varBlue = Int(cValue / 65536)
cValue = cValue Mod 65536
varGreen = Int(cValue / 256)
cValue = cValue Mod 256
varRed = cValue
End Sub
Pass the value you get from the GetPixel function, then the variable to store the red value in, then green variable, then blue.
Hope this helps,
cjqp
When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.
-
Mar 31st, 2004, 02:56 PM
#3
-
Mar 31st, 2004, 02:58 PM
#4
Hyperactive Member
Originally posted by manavo11
Probably a bunch of APIs... I guess you'll need the following APIs :
GetForegroundWindow or GetActiveWindow
GetDC
GetPixel
I don't mean to sound rude but, did you actually read his post? He wants to know how to get a color from a pixel, not from a certain window.
cjqp
When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.
-
Mar 31st, 2004, 03:08 PM
#5
-
Mar 31st, 2004, 03:09 PM
#6
Hyperactive Member
Ahhh, right, forgot about needing the hDC, yeah, I'd go with GetDesktopWindow for that.
cjqp
When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.
-
Mar 31st, 2004, 03:15 PM
#7
VB Code:
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long) _
As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RGBA
r As Byte
g As Byte
b As Byte
a As Byte
End Type
Private Type RGBL
rgb As Long
End Type
Private Sub Timer1_Timer()
Dim clr As Long
Dim rgb As RGBA
Dim t As RGBL
Dim p As POINTAPI
Call GetCursorPos(p)
clr = GetPixel(GetWindowDC(0&), p.x, p.y)
t.rgb = clr
LSet rgb = t
Me.BackColor = clr
Me.Caption = "R:" & rgb.r & ", G:" & rgb.g & ", B:" & rgb.b
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 31st, 2004, 03:51 PM
#8
Why do you declare a?
VB Code:
Private Type RGBA
r As Byte
g As Byte
b As Byte
a As Byte
End Type
Has someone helped you? Then you can Rate their helpful post. 
-
Mar 31st, 2004, 03:52 PM
#9
Why not?
Helps me to better remember what's what.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 31st, 2004, 04:08 PM
#10
-
Mar 31st, 2004, 05:19 PM
#11
A is for the alpha.
Its the alpha bit.. Ha ha, get it?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 31st, 2004, 06:01 PM
#12
Hyperactive Member
*rolls eyes*, anyway, blade, where in your code does it separate the values??
cjqp
Last edited by cjqp; Mar 31st, 2004 at 06:05 PM.
When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.
-
Mar 31st, 2004, 06:08 PM
#13
Right here...
Code:
t.rgb = clr
LSet rgb = t
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 31st, 2004, 09:17 PM
#14
Hyperactive Member
But how the heck does that split? There is no Property Let or the like that would split it.
cjqp
When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.
-
Mar 31st, 2004, 10:14 PM
#15
Originally posted by cjqp
But how the heck does that split? There is no Property Let or the like that would split it.
cjqp
In VB, you can exchange data in compatible UDTs. A Long is 4 bytes, so if you have one Type with a Long, and one with 4 Bytes, you can break that Long into its individual Bytes.
Red byte
Green byte
Blue byte
Alpha byte
See it?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 31st, 2004, 10:17 PM
#16
Hyperactive Member
ahhh, tyvm. Up until your example, my code was by far the shortest for this type of thing.
cjqp
When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.
-
Apr 2nd, 2004, 04:12 AM
#17
-
Apr 2nd, 2004, 10:00 AM
#18
I suppose technically you don't need it as part of the Type, since it should still just copy over the first 3 bytes anyway, but again, its good to know what's what.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 2nd, 2004, 05:52 PM
#19
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|