• <bdo id='lkNgm'></bdo><ul id='lkNgm'></ul>

    1. <i id='lkNgm'><tr id='lkNgm'><dt id='lkNgm'><q id='lkNgm'><span id='lkNgm'><b id='lkNgm'><form id='lkNgm'><ins id='lkNgm'></ins><ul id='lkNgm'></ul><sub id='lkNgm'></sub></form><legend id='lkNgm'></legend><bdo id='lkNgm'><pre id='lkNgm'><center id='lkNgm'></center></pre></bdo></b><th id='lkNgm'></th></span></q></dt></tr></i><div id='lkNgm'><tfoot id='lkNgm'></tfoot><dl id='lkNgm'><fieldset id='lkNgm'></fieldset></dl></div>

      <small id='lkNgm'></small><noframes id='lkNgm'>

      <tfoot id='lkNgm'></tfoot>
      <legend id='lkNgm'><style id='lkNgm'><dir id='lkNgm'><q id='lkNgm'></q></dir></style></legend>
    2. 在 Windows 7 上使用 Python 快速获取屏幕上某些像素的颜色

      时间:2023-07-23
        <tbody id='j2ifv'></tbody>

      1. <small id='j2ifv'></small><noframes id='j2ifv'>

        <legend id='j2ifv'><style id='j2ifv'><dir id='j2ifv'><q id='j2ifv'></q></dir></style></legend>
        <i id='j2ifv'><tr id='j2ifv'><dt id='j2ifv'><q id='j2ifv'><span id='j2ifv'><b id='j2ifv'><form id='j2ifv'><ins id='j2ifv'></ins><ul id='j2ifv'></ul><sub id='j2ifv'></sub></form><legend id='j2ifv'></legend><bdo id='j2ifv'><pre id='j2ifv'><center id='j2ifv'></center></pre></bdo></b><th id='j2ifv'></th></span></q></dt></tr></i><div id='j2ifv'><tfoot id='j2ifv'></tfoot><dl id='j2ifv'><fieldset id='j2ifv'></fieldset></dl></div>
            <tfoot id='j2ifv'></tfoot>

              <bdo id='j2ifv'></bdo><ul id='j2ifv'></ul>
                本文介绍了在 Windows 7 上使用 Python 快速获取屏幕上某些像素的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要获取屏幕上或活动窗口中某些像素的颜色,我需要这样做快速.我试过使用 win32gui 和 ctypes/windll,但它们太慢了.这些程序中的每一个都获得 100 像素的颜色:

                I need to get the color of some pixels on the screen or from the active window, and I need to do so quickly. I've tried using win32gui and ctypes/windll, but they're much too slow. Each of these programs gets the color of 100 pixels:

                import win32gui
                import time
                time.clock()
                for y in range(0, 100, 10):
                    for x in range(0, 100, 10):
                        color = win32gui.GetPixel(win32gui.GetDC(win32gui.GetActiveWindow()), x , y)
                print(time.clock())
                

                from ctypes import windll
                import time
                time.clock()
                hdc = windll.user32.GetDC(0)
                for y in range(0, 100, 10):
                    for x in range(0, 100, 10):
                        color = windll.gdi32.GetPixel(hdc, x, y)
                print(time.clock())
                

                每个都需要大约 1.75 秒.我需要这样的程序花费不到 0.1 秒.是什么让它这么慢?

                Each of these takes about 1.75 seconds. I need a program like this to take less than 0.1 seconds. What's making it so slow?

                我正在使用 Python 3.x 和 Windows 7.如果您的解决方案需要我使用 Python 2.x,请将我链接到显示如何同时安装 Python 3.x 和 2.x 的文章.我看了看,但不知道该怎么做.

                I'm working with Python 3.x and Windows 7. If your solution requires I use Python 2.x, please link me to an article showing how to have Python 3.x and 2.x both installed. I looked, but couldn't figure out how to do this.

                推荐答案

                我遇到了同样的问题,并解决了它(在 Java 中,在 C# 中).解决方案背后的主要思想是 GetPixel from screen 很慢,你无法解决这个问题.但由于您需要一些像素,您可以一次获得一堆.

                I had this same exact problem, and solved it (in Java, in C#). The main idea behind the solution is GetPixel from screen is slow, and you can't fix that. But as you need some pixels, you can get a bunch of them all at once.

                获得 64 像素所需的时间快了 98 倍.

                The time that it took to get 64 pixels was 98 times faster.

                这篇关于在 Windows 7 上使用 Python 快速获取屏幕上某些像素的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使 Python 脚本在 Windows 上运行而不指定“.py";延期 下一篇:添加“django-admin.py"Windows 7 上的命令行路径

                相关文章

                  <small id='UwF5h'></small><noframes id='UwF5h'>

                  <i id='UwF5h'><tr id='UwF5h'><dt id='UwF5h'><q id='UwF5h'><span id='UwF5h'><b id='UwF5h'><form id='UwF5h'><ins id='UwF5h'></ins><ul id='UwF5h'></ul><sub id='UwF5h'></sub></form><legend id='UwF5h'></legend><bdo id='UwF5h'><pre id='UwF5h'><center id='UwF5h'></center></pre></bdo></b><th id='UwF5h'></th></span></q></dt></tr></i><div id='UwF5h'><tfoot id='UwF5h'></tfoot><dl id='UwF5h'><fieldset id='UwF5h'></fieldset></dl></div>

                  <legend id='UwF5h'><style id='UwF5h'><dir id='UwF5h'><q id='UwF5h'></q></dir></style></legend>

                    • <bdo id='UwF5h'></bdo><ul id='UwF5h'></ul>

                  1. <tfoot id='UwF5h'></tfoot>