GVKun编程网logo

在Windows上使用python截屏的最快方法(python windows api截图)

14

本文将介绍在Windows上使用python截屏的最快方法的详细情况,特别是关于pythonwindowsapi截图的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时

本文将介绍在Windows上使用python截屏的最快方法的详细情况,特别是关于python windows api截图的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于c – 如何在WIndows上使用Cython编译Pyparsing?、python – 为什么我的当前目录不会出现在Windows上使用pytest的路径中?、python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?、windows-7 – 如何在Windows 7上使用Python 3和httplib2调用AWS?的知识。

本文目录一览:

在Windows上使用python截屏的最快方法(python windows api截图)

在Windows上使用python截屏的最快方法(python windows api截图)

在Windows上截图的最快方法是什么?PIL.ImageGrab是相当慢的..花费4-5秒钟才能获得同一小窗口的30个屏幕截图。拍摄整个桌面的屏幕截图甚至更慢。

答案1

小编典典

您可以直接使用win32 API。

1)首先将焦点放在您要为其截屏的应用程序上。连结文字 “焦点问题在另一个问题中处理”)

2)Win32 API可以帮助截图:

import win32guiimport win32ui hwnd = win32gui.FindWindow(None, windowname)wDC = win32gui.GetWindowDC(hwnd)dcObj=win32ui.CreateDCFromHandle(wDC)cDC=dcObj.CreateCompatibleDC()dataBitMap = win32ui.CreateBitmap()dataBitMap.CreateCompatibleBitmap(dcObj, w, h)cDC.SelectObject(dataBitMap)cDC.BitBlt((0,0),(w, h) , dcObj, (0,0), win32con.SRCCOPY)dataBitMap.SaveBitmapFile(cDC, bmpfilenamename)# Free ResourcesdcObj.DeleteDC()cDC.DeleteDC()win32gui.ReleaseDC(hwnd, wDC)win32gui.DeleteObject(dataBitMap.GetHandle())

c – 如何在WIndows上使用Cython编译Pyparsing?

c – 如何在WIndows上使用Cython编译Pyparsing?

我试图在我的 Windows机器上编译Pyparsing但是遇到以下错误:
python setup.py build_ext --inplace
running build_ext
cythoning pyparsing.pyx to pyparsing.c

Error compiling Cython file:
------------------------------------------------------------
...
       If C{include} is set to true,the matched expression is also parsed (the
skipped text
       and matched expression are returned as a 2-element list).  The C{ignore}
       argument is used to define grammars (typically quoted strings and comment
s) that
       might contain false matches.
    """
    def __init__( self,other,include=False,ignore=None,failOn=None ):
                              ^
------------------------------------------------------------

pyparsing.pyx:2764:31: Expected an identifier,found 'include'

Error compiling Cython file:
------------------------------------------------------------
...
    def __init__( self,failOn=None ):
        super( SkipTo,self ).__init__( other )
        self.ignoreExpr = ignore
        self.mayReturnEmpty = True
        self.mayIndexError = False
        self.includeMatch = include
                           ^
------------------------------------------------------------

pyparsing.pyx:2769:28: Expected an identifier or literal
building 'pyparsing' extension
creating build
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcpyparsing.c /Fobuild\t
emp.win32-2.7\Release\pyparsing.obj
pyparsing.c
pyparsing.c(1) : Fatal error C1189: #error :  Do not use this file,it is the re
sult of a Failed Cython compilation.
error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' fa
iled with exit status 2

我使用Microsoft Visual C 2008 Express版进行了编译,使用的Pyparsing模块是最新版本.请问,有谁知道如何使这项工作?

解决方法

先生,我按照你的说法做了,但仍然有编译时警告:
    python setup.py build_ext --inplace
    running build_ext
    cythoning pyparsing.pyx to pyparsing.c
    warning: pyparsing.pyx:413:8: Unreachable code
    building 'pyparsing' extension
    creating build
    creating build\temp.win32-2.7
    creating build\temp.win32-2.7\Release
    C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
    3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcpyparsing.c /Fobuild\t
    emp.win32-2.7\Release\pyparsing.obj
    pyparsing.c
    C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCRE
    MENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild /EXPORT:initpyp
    arsing build\temp.win32-2.7\Release\pyparsing.obj /OUT:C:\Users\iProsper\Desktop
    \pyparsing\pyparsing.pyd /IMPLIB:build\temp.win32-2.7\Release\pyparsing.lib /MAN
    IFESTFILE:build\temp.win32-2.7\Release\pyparsing.pyd.manifest
       Creating library build\temp.win32-2.7\Release\pyparsing.lib and object build\
    temp.win32-2.7\Release\pyparsing.exp
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe -nologo -manifest build
    \temp.win32-2.7\Release\pyparsing.pyd.manifest -outputresource:C:\Users\iProsper
    \Desktop\pyparsing\pyparsing.pyd;2

警告实际上在第4行:警告:pyparsing.pyx:413:8:无法访问的代码.然后我将该行改为:

    def __getattr__( self,name ):
            if True: #name not in self.__slots__:
                if name in self.__tokdict:
                    if name not in self.__accumNames:
                        return self.__tokdict[name][-1][0]
                    else:
                        return ParseResults([ v[0] for v in self.__tokdict[name] ])
                else:
                    return ""
            else:
                return None

然后重新编译它.我注意到的一件事是,即使我发出警告和编辑,它们都成功编译,但是当我尝试使用以下代码进行测试时:

    from pyparsing import Word,alphas
    greet = Word(alphas) + ',' + Word(alphas) + '!'
    greeting = greet.parseString('Hello,World!')
    print greeting

我收到以下错误:

    Traceback (most recent call last):
      File "C:\nwaomachux\build_pyparsing\checkout.py",line 1,in 
        from pyparsing import Word,alphas
      File "pyparsing.pyx",line 3414,in init pyparsing (pyparsing.c:100064)
    AttributeError: 'builtin_function_or_method' object has no attribute 'ANY_VALUE'

我会进一步修改文件并发送给你检查它,但我只有几个小时的Pyparsing,所以我还没有掌握完整的源代码.

我不知道将withAttribute.ANY_VALUE = object()移动到def withAttribute(args,* attrDict)的开头是什么效果:function表示.请问,它有什么问题?谢谢.

python – 为什么我的当前目录不会出现在Windows上使用pytest的路径中?

python – 为什么我的当前目录不会出现在Windows上使用pytest的路径中?

我有以下文件夹结构;

myapp\
  myapp\
     __init__.py
  tests\
     test_ecprime.py

而我的前任是

C:\Users\wwerner\programming\myapp\

我有以下测试设置:

import pytest
import sys
import pprint

def test_cool():
    pprint.pprint(sys.path)
    assert False

这会产生以下路径:

['C:\\Users\\wwerner\\programming\\myapp\\tests','C:\\Users\\wwerner\\programming\\envs\\myapp\\Scripts','C:\\Windows\\system32\\python34.zip','C:\\python34\\DLLs','C:\\python34\\lib','C:\\python34','C:\\Users\\wwerner\\programming\\envs\\myapp','C:\\Users\\wwerner\\programming\\envs\\myapp\\lib\\site-packages']

当我尝试导入myapp时,我收到以下错误:

ImportError: No module named 'ecprime'

所以看起来它并没有将当前目录添加到我的路径中.

通过将我的导入行更改为如下所示:

import sys
sys.path.insert(0,'.')
import myapp

然后我可以毫无问题地导入myapp.

为什么运行pytest时我的当前目录没有显示在路径中?是我唯一要插入的解决方法.进入sys.path? (如果重要,我正在使用Python 3.4)

解决方法

啊啊!

在比较了我的cookiecutter repo的布局之后,事实证明它比这更简单(也更好).

tests/
    __init__.py
    test_myapp.py

将__init__.py文件简单添加到我的测试目录允许我从我的主目录运行py.test.

python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?

python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?

QProcess.pid()的文档说:

Returns the native process identifier for the running process,if available. If no process is currently running,0 is returned.

这是什么意思?

这段代码用来解释我的困惑.我使用的是Python 2.7.9,PyQt 4和Windows 7:

import  sys,os,time
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class testLaunch(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.process = QProcess(self)
        self.process.start('calc')
        self.process.waitForStarted(1000)
        print "PID:",int(self.process.pid())

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = testLaunch()
    main.show()
    sys.exit(app.exec_())

这将按预期启动Windows计算器应用程序.在任务管理器中,它显示以下内容:

Calculator PID

这显示我的PID为8304.虽然我的应用程序的print语句显示:

PID: 44353984

这代表了什么?它与任务管理器报告的8304 PID相比如何?

解决方法

在Unix系统上,pid将是一个qint64,但在Windows上它将是这样的结构:

typedef struct _PROCESS_informatION {
  HANDLE hProcess;
  HANDLE hThread;
  DWORD  dwProcessId;
  DWORD  dwThreadId;
} PROCESS_informatION,*LPPROCESS_informatION;

PyQt将为这样的结构返回一个sip.voidptr,这就是为什么当你用int()转换它时你会看到这个奇怪的值.你想要的实际pid是dwProcessId,所以你需要使用像ctypes这样的东西来提取它.

这是一些完全未经测试的代码,可以完成这项工作:

import ctypes

class WinProcInfo(ctypes.Structure):
    _fields_ = [
        ('hProcess',ctypes.wintypes.HANDLE),('hThread',('dwProcessID',ctypes.wintypes.DWORD),('dwThreadID',]
LPWinProcInfo = ctypes.POINTER(WinProcInfo)

lp = ctypes.cast(int(self.process.pid()),LPWinProcInfo)
print(lp.contents.dwProcessID)

windows-7 – 如何在Windows 7上使用Python 3和httplib2调用AWS?

windows-7 – 如何在Windows 7上使用Python 3和httplib2调用AWS?

我使用httplib2来调用Amazon Web Services(AWS):

http = httplib2.Http(cache='.cache')
response,content = http.request('https://sdb.amazonaws.com/...')

但它没有找到CA(我认为):

File "C:\python32\lib\site-packages\httplib2\__init__.py",line 1059,in request self.disable_ssl_certificate_validation)
File "C:\python32\lib\site-packages\httplib2\__init__.py",line 772,in __init__ context.load_verify_locations(ca_certs)
IOError: [Errno 2] No such file or directory

我的问题:

>我需要做些什么来配置我的操作系统和环境才能使用它?
>我已经看过很多关于确保在Python 2中为SSL构建套接字库的帖子;这适用于Python 3吗?

谢谢!

解决方法

httplib2 / python3文件夹缺少cacerts.txt,因此不会将其复制到Python / lib文件夹中.我手动复制了文件,一切正常.这是httplib2的一个已知问题.

我们今天的关于在Windows上使用python截屏的最快方法python windows api截图的分享已经告一段落,感谢您的关注,如果您想了解更多关于c – 如何在WIndows上使用Cython编译Pyparsing?、python – 为什么我的当前目录不会出现在Windows上使用pytest的路径中?、python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?、windows-7 – 如何在Windows 7上使用Python 3和httplib2调用AWS?的相关信息,请在本站查询。

本文标签: