karthik prapanna
karthik prapanna

Reputation: 1

why win32gui's getpixel() is lot slower in windows 10 compared to windows 7 ? is there any solution?

I know that using win32gui is the fastest way to get the pixel data compared to PIL and other such libraries. Up until now I was executing my code in windows 7 laptop(old) where it was working very fast but recently I bought a new laptop(processor is superior to my older one) which came with Windows 10 inbuilt but in windows 10 the same program is a lot slower and after having a closer look I understood that the getpixel part of code is making the entire program slow. so to be sure I calculated the time taken for the same code to execute in both windows 10 & windows 7 and what I found is the same code took just 0.03 seconds in windows 7 whereas it took 17 seconds in windows 10(even after having higher processing power). Is there any solution for this? is there any separate library for windows 10 which is faster?

from win32 import win32gui
import time

a = []


def getList():
    temp = []

    i_desktop_window_id = win32gui.GetDesktopWindow()
    i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id)
    long_colour = win32gui.GetPixel(i_desktop_window_dc, 100,100)
    i_colour = int(long_colour)
    px_tuple=((i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff))
    temp.append(px_tuple)
    win32gui.ReleaseDC(i_desktop_window_id, i_desktop_window_dc)    
    return temp

start = time.perf_counter()
for i in range(1000):
    a= getList()
stop = time.perf_counter()
print(stop - start)

Upvotes: 0

Views: 245

Answers (0)

Related Questions