title: Scan image pixel by pixel in VBA
body: <p>There is a near exact question here 
  <a href="https://stackoverflow.com/questions/16528319/read-pixel-colors-of-an-image">Read pixel colors of an image</a></p>
  
  <p>The Op actually asks the same question as I'm asking for. But accepts an answer that is nearly there but not quite.. The code below (taken from that thread) does everything I need bar the pixel by pixel bit. If you click on an image it will give you the colour at the click site. As I want to scan the whole picture I though I'd just do an X Y scan and put the sequential X and Y's in instead of the returned X and Y of the GetCursorPos call. But how to get left position and width (for example) in pixels to start the scan? What would I put in my for next loop to address each pixel ?</p>
  
  <p>So to clarify my question. 
  How to change the code below to scan every pixel of the image not just the clicked cursor position.  Thanks  </p>
  
  <pre><code>#If VBA7 Then
      Private Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hdc As LongPtr, ByVal x As Long, ByVal y As Long) As Long
      Private Declare PtrSafe Function GetCursorPos Lib "user32" (ByRef lpPoint As POINT) As LongPtr
      Private Declare PtrSafe Function GetWindowDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
  #Else
      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" (ByRef lpPoint As POINT) As Long
      Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  #End If
  Private Type POINT
      x As Long
      y As Long
  End Type
  
  Sub Picture1_Click()
      Dim pLocation As POINT
      Dim lColour As Long
  
      Dim lDC As Variant
      lDC = GetWindowDC(0)
      Call GetCursorPos(pLocation)
      lColour = GetPixel(lDC, pLocation.x, pLocation.y)
      Range("a1").Interior.Color = lColour
  End Sub
  </code></pre>