Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to speed up set pixel bitmap?
#1
[moved from General]

I'm curious about how the scan and wait functions work. they can work in the background and quickly find images even in windows that don't support PrintWindow.

I tried to make a function that can capture the screen in a window that runs in the background, but this window does not support PrintWindow. it will only get black

after I did some research, I found the SetPixel function in gdi32.dll. with this reference I can declare the dll function in my macros, then I use this to get every pixel in the area in the window.

but I think this method is too slow when compared to scan, wait, or CaptureImageOnScreen. to get 155 x 37 image I need up to 3 seconds to complete it, whereas CaptureImageOnScreen can be finished in less than 1 second

how can i speed up the process of this function?

Thanks

Function BackgroundScreenshot
Code:
Copy      Help
function hwnd x y width height str'path

dll gdi32 #SetPixel hdc x y color

RECT r
r.left = x
r.top = y
r.right = x + width
r.bottom = y + height
__MemBmp m.Create(width height)

int i j
for(j r.top r.bottom)
,for(i r.left r.right)
,,_i=FastPixel(i j hwnd 1)
,,SetPixel m.dc (i - r.left) (j - r.top) _i
SaveBitmap(m.bm path)
#2
Lightbulb 
SOLVED!
I just realize CaptureImageOnScreen using

Function CaptureImageOnScreen
Code:
Copy      Help
__MemBmp b
if(!b.Create(width height 1 x y)) ret

which is using srcdc of current screen, i think

while my function not using any srcdc

Function BackgroundScreenshot
Code:
Copy      Help
__MemBmp m.Create(width height)

so i change it to using dc of window that i want to capture, then it works like CaptureImageOnScreen. Very fast, it finished at same second

Function BackgroundScreenshot
Code:
Copy      Help
__MemBmp m.Create(width height GetDC(hwnd) x y)

and because it dont need to get and set pixel by pixel anymore, so i remove the dll declaration
#3
Don't forget ReleaseDC.
#4
Thank you for reminding me


Forum Jump:


Users browsing this thread: 1 Guest(s)