Results 1 to 5 of 5

Thread: Need some advanced graphics help

  1. #1

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935

    Post

    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.

  2. #2
    Junior Member
    Join Date
    Dec 1999
    Posts
    22

    Post

    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

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try this:
    Code:
    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
    [email protected]
    [email protected]


  4. #4

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935

    Post

    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.

  5. #5
    Guest
    Just add a picture box to the form and then add the following to form load (or to another event that you want):-

    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width