Alternative to GetPixel

Started by
1 comment, last by iMalc 14 years, 7 months ago
I'm trying to read portions of the desktop in my program, but I am unsure as to how to go about doing this in a manner that is faster than using GetPixel for each individual pixel. At one point I was grabbing a rectangle using BitBlt and storing it into a BITMAP, but that was equally slow. The windows magnifier program (start->programs->accessories->accessibility) seems to do it virtually instantly, but I figured that maybe it's not actually reading the screen data into memory that the program itself accesses, eg: it's simply blitting video memory around, instead of to system memory. Thanks.
Advertisement
Fastest way I know of:

1) Create new DC linked to bitmap object
2) BitBlit the screen DC data into bitmap's DC
3) Use GetDIBits to copy the data from bitmap DC into raw data buffer
You can't successfull use GetPixel for any amount of bulk image processing.
It's like wanting to buy 1 cup of rice by repeatedly going to the shop to buy a single grain, carrying that home, and going back to the shop to buy the next grain... etc
I.e. It takes forever because it has such a high overhead per call. A BitBlt on the other hand would usually be very fast. If the bit-depths of the bitmaps are different etc then it can slow down a litle, but it still shouldn't be close to as slow as GetPixel calls unless you perhaps were using it for a very small area.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement