PDA

Click to See Complete Forum and Search --> : Need some advanced graphics help


filburt1
Jan 20th, 2000, 04:04 AM
I need to find out how to get the color value (long) of a pixel on the screen and how to set a pixel of a certain color to the screen. I looked at the SetPixel and GetPixel API, but they both require handles, and I don't know if there even is a handle for the entire screen. Any help?

------------------
Arien Talabac, author of Tiny Clock, the skinnable alarm clock for Windows--check it out at http://tinyclock.tsx.org.

B4
Jan 20th, 2000, 04:12 AM
The handle for the screen is the HDC. I have never done graphics programming in VB, but I have used the GetPixel and SetPixel functions in C before. They require you to pass the source from which you want to get the pixel, which is declared and set in the begining. Both functions are very slow for get the pixel value of the whole screen.

-B4

Aaron Young
Jan 20th, 2000, 04:22 AM
Try this:

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

Private lDC As Long

Private Sub Form_Load()
lDC = GetWindowDC(0) 'Desktop
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim tPOINT As POINTAPI
Dim sColor As String

Call GetCursorPos(tPOINT)
sColor = Right("000000" & Hex$(GetPixel(lDC, tPOINT.x, tPOINT.y)), 6)
Caption = "R:" & Right$(sColor, 2) & " G:" & Mid$(sColor, 3, 2) & " B:" & Left$(sColor, 2)
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

filburt1
Jan 20th, 2000, 04:37 AM
Way cool code!
OK, I got it to return hex values for the mouse x,y, but how do I set pixels (and later, text) to the screen?

------------------
Arien Talabac, author of Tiny Clock, the skinnable alarm clock for Windows--check it out at http://tinyclock.tsx.org.

Apr 18th, 2000, 12:40 AM
Just add a picture box to the form and then add the following to form load (or to another event that you want):-



Me.Show

Picture1.ScaleMode = vbPixels
Picture1.DrawWidth = 1
Picture1.ForeColor = RGB(255, 0, 0)
Picture1.PSet (10, 10)



The above will create a red dot, 1 pixel in size at the point 10,10 in the picture box. You can just repeatedly call the picture1.pset line to add more dots to the picture.

Hope this helps.