QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Zeppelin on September 06, 2018, 01:39:47 am

Title: Grabbing data outside of a programs screen
Post by: Zeppelin on September 06, 2018, 01:39:47 am
Why doesn't QB64 allow for reading pixels (getting RGB values) outside of the program window?
There are several other languages that allow this type of data collection why not QB64.

Thanks
Zeppelin
Title: Re: Grabbing data outside of a programs screen
Post by: Cobalt on September 06, 2018, 01:44:04 am
Technically you can, if you do a screen copy and read the POINT from that handle. I've used such method more than once for automating certain tasks, and letting the computer play through some repetitive game parts.
Title: Re: Grabbing data outside of a programs screen
Post by: Cobalt on September 06, 2018, 01:45:53 am
_SCREENIMAGE is the command your looking for.
Title: Re: Grabbing data outside of a programs screen
Post by: Petr on September 06, 2018, 11:39:00 am
Allows. Even in two ways. One is backwards compatible with Quick Basic, using POINT, the other is very fast with MEM. You can read the color values on any program screen and on the desktop. The snapshot of the workspace do _SCREENIMAGE (it does not work in Linux), and the motion on virtual screens in turn allows _DEST and _SOURCE so the user sees SCREEN 0 while the program reads an image.

Code: QB64: [Select]
  1. PRINT "You are on text screen"
  2. DIM m AS _MEM, kolor AS _UNSIGNED LONG, all_pixels AS LONG, N AS _MEM
  3.  
  4. m = _MEMIMAGE(i&)
  5. PRINT "Reading color values used on desktop. Press key..."
  6.  
  7. N = _MEMIMAGE(0)
  8.  
  9. FOR all_pixels = 0 TO (_DESKTOPWIDTH * _DESKTOPHEIGHT) * 4 - 4
  10.     _MEMGET m, m.OFFSET + all_pixels, kolor
  11.     _MEMPUT N, N.OFFSET + all_pixels, kolor
  12.  
  13.  
  14. PRINT "MEM output. Press any key for do the same using POINT and PSET..."
  15. a& = _DEST
  16.  
  17.  
  18.  
  19.  
  20.     FOR X = 0 TO _DESKTOPWIDTH
  21.         _SOURCE i&
  22.         kolor& = POINT(X, Y)
  23.         _DEST image&
  24.         PSET (X, Y), kolor&
  25. NEXT X, Y
  26.  
  27. PRINT "Press key for show image draw by PSET"
  28. SCREEN image&
  29. PRINT "Press key for end"
  30.  
  31. _FREEIMAGE image&
  32.