Results 1 to 3 of 3

Thread: Problem with GetPixel - help please

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Problem with GetPixel - help please

    The routine I have below I want to get the pixel of the screen. It returns nothing here. If I move the GetPixel call out of the loop, it returns something.

    Any idea what I'm doing wrong or a better way of this?

    Thanks!

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim hDC As Long
    3. Dim H1 As Long
    4. Dim W1 As Long
    5. Dim Z As Long
    6.   H1 = Screen.Height / Screen.TwipsPerPixelY
    7.   W1 = Screen.Width / Screen.TwipsPerPixelX
    8.   Dim X As Long
    9.   Dim Y As Long
    10.   hDC = GetDC(0) 'get desktop dc
    11.  
    12.   For Y = 1 To Y1 - 10
    13.     For X = 1 To H1 - 10
    14.      
    15.       Z = GetPixel(hDC, X, Y)
    16.       Memo1.Text = Memo1.Text & Trim(Str(Z))
    17.      
    18.     Next X
    19.   Next Y
    20.  
    21. End Sub

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Problem with GetPixel - help please

    you're using Y1 rather than W1 (or whatever it should be) in the first For - use Option Explicit at the top of the form to catch these errors!

  3. #3
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Problem with GetPixel - help please

    Also, when using GetDC(), you need to use ReleaseDC() when you're done with the DC. That allows the DC to be used again.
    VB Code:
    1. Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    2.  
    3. 'ex. in your sub, when you're done with the DC
    4. Call ReleaseDC(Me.hwnd, hdc)
    Last edited by Keith_VB6; Jun 22nd, 2006 at 12:32 PM. Reason: forgot the [vbcode]
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

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