GetPixel
slow for two reasons:
Since you are viewing the screen, each call to GetPixel
results in a transaction to the video driver, which in turn takes the pixel data from the video memory.
In constrast mode, using GetPixel
on the DIB is much faster.
In any case, GetPixel
performs several actions, including cropping / converting coordinates, etc.
So, if you use to request many pixel values โโat the same time, you should try to organize this in one transaction with the GDI / video driver.
Using GDI, you must create a DIB of the appropriate size (see CreateDIBSection
). Once created, you will be given a direct pointer to the image bit data. Then copy part of the image to your DIB (see BitBlt
). Also remember to call GdiFlush
before you actually check the contents of the DIB (as video drivers can do asynchronous drawing).
Using GD +, you can do the same with a slightly simpler syntax.
valdo source share