I’m trying to do something like this:
If RGBSurface.Pixel(20,20) = &HFFFFFF Then
MsgBox("True!")
Else
MsgBox("False!")
End If
Possible? Just want to use RGBSurface on the desktop.
I’m trying to do something like this:
If RGBSurface.Pixel(20,20) = &HFFFFFF Then
MsgBox("True!")
Else
MsgBox("False!")
End If
Possible? Just want to use RGBSurface on the desktop.
An RGBSurface can only be created from a Picture object. Depending on what the source of the pixel you’re reading is this may mean that the RGBSurface is not available to you or that some extra work is needed to get a Picture of it.
When you say
Do you mean get a pixel from the screen? Like pulling a single pixel out of a screenshot?
In older versions sytem.pixel could be used for what Chris McGhee suggests, but I checked the documentation and it’s no longer available (probably deprecated?)
What’s the substitute for system.pixel?
Thanks
As far as I know, there isn’t one. I have a Windows-specific code snippet for capturing the user’s desktop into a Picture if that would be useful.
So what I would be doing is taking a screenshot of my screen, and then using RGBSurface on that screenshot? Would that be faster than using System.Pixel?
@Andrew L. - yes please!!
This function returns a Picture (which you can get the RGBSurface for) of the specified rectangle on the user’s desktop. To capture the whole screen(s) use the Screen method to determine the width and height of the screen(s). X and Y are relative to the top left corner of Screen(0).
Function CaptureRect(X As Integer, Y As Integer, Width As Integer, Height As Integer) As Picture
#If TargetWin32 Then
Declare Function GetDesktopWindow Lib "User32" () As Integer
Declare Function GetDC Lib "User32" (HWND As Integer) As Integer
Declare Function BitBlt Lib "GDI32" (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer, nHeight As Integer, DCdource As Integer, xSource As Integer, ySource As Integer, rasterOp As Integer) As Boolean
Declare Function ReleaseDC Lib "User32" (HWND As Integer, DC As Integer) As Integer
Const SRCCOPY = &h00CC0020
Const CAPTUREBLT = &h40000000
Dim screenCap As New Picture(Width, Height, 24)
Dim deskHWND As Integer = GetDesktopWindow()
Dim deskHDC As Integer = GetDC(deskHWND)
Call BitBlt(screenCap.Graphics.Handle(screenCap.Graphics.HandleTypeHDC), 0, 0, Width, Height, DeskHDC, X, Y, SRCCOPY Or CAPTUREBLT)
Call ReleaseDC(DeskHWND, deskHDC)
#Endif
Return screenCap
End Function
Many thanks Andrew