The problem in your case are:
GetPixel() will read from visible desktop memory and must locked every memory access pixel by pixel.
The driver modell are changed in WIN 10 and you have to use DirectX for direct video memory acceess.
But you can copy the whole desktop once and get the pixel as fast as possible.
Joshy
Code: Select all
#include "windows.bi"
function getPixelFast(byval x as long,byval y as long) as ulong
static as HDC memDC
static as HDC screenDC
static as BITMAPINFO bi
static as HBITMAP bmp
static as long w,h
static as any ptr pixels=cptr(any ptr,&HC0FFE)
static as ulong ptr row
if (pixels=&HC0FFE) then
screenDC = GetDC(HWND_DESKTOP)
w = GetSystemMetrics (SM_CXSCREEN)
h = GetSystemMetrics (SM_CYSCREEN)
windowtitle " " & w & "," & h
pixels = allocate(w*h*4)
memDC = CreateCompatibleDC(screenDC)
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER)
bi.bmiHeader.biWidth = w
bi.bmiHeader.biHeight = -h
bi.bmiHeader.biPlanes = 1
bi.bmiHeader.biBitCount = 32
bi.bmiHeader.biCompression = BI_RGB
bi.bmiHeader.biSizeImage = w * h * 4
bmp = CreateDIBSection(memDC, @bi, DIB_RGB_COLORS, @pixels, NULL, NULL)
SelectObject(memDC,bmp)
BitBlt(memDC,0,0,w,h,screenDC,0,0,SRCCOPY)
row = pixels
end if
if x<0 or x>w-1 then return -1
if y<0 or y>h-1 then return -1
return row[y*w+x]
end function
const scr_w = 640
const scr_h = 480
screenres scr_w,scr_h,32
var tStart = Timer()
for y as long=0 to scr_h-1
for x as long=0 to scr_w-1
pset (x,y),getPixelFast(x,y)
next
next
var tEnd = Timer()
windowtitle "time: " & tEnd - tStart
sleep