如何使用wxpython拍摄整个屏幕截图

问题描述 投票:0回答:2

我正在设置图像处理工具,其输入应为屏幕截图。

wx python屏幕截图功能在尺寸正确但图像被缩放的情况下起作用,因此不能捕获整个屏幕。

def taking_screenshot():
    screen = wx.ScreenDC()
    size=screen.GetSize()
    bmp = wx.Bitmap(size[0],size[1])
    mem=wx.MemoryDC(bmp)
    mem.Blit(0,0,size[0],size[1],screen,0,0)
    del mem
    bmp.SaveFile('screenshot_for_working.PNG',wx.BITMAP_TYPE_PNG)
   ('window',cv2.imread('screenshot_for_working.PNG') )

打开的图像窗口覆盖了整个屏幕,实际图像被缩放,因此仅部分显示屏幕

python opencv wxpython
2个回答
0
投票

非常感谢您的想法。我想到了。在我的基本屏幕设置中,所有放大的内容都设置为150%。还是谢谢。


0
投票

这里有一些小的调整应该可以解决。使用widthheight之类的措辞,以便您可以跟踪哪些值到达何处。

print (width, height),您可以与DisplaySize进行比较,如果不正确,则应自己定义宽度/高度。

def taking_screenshot():
    screen = wx.ScreenDC()
    size=screen.GetSize()

    print (wx.DisplaySize())                # debugging: see if pixel values are okay.

    width = size[0]
    height = size[1]

    print (width, height)                    # compare with above values.

    bmp = wx.EmptyBitmap(width,height)       # use EmptyBitmap here instead of wx.Bitmap.
    mem=wx.MemoryDC(bmp)
    mem.SelectObject(bmp)                   # tell mem to use the actual bitmap
    mem.Blit(0,0,width, height,screen,0,0)
    del mem
    bmp.SaveFile('screenshot_for_working.PNG',wx.BITMAP_TYPE_PNG)
   ('window', cv2.imread('screenshot_for_working.PNG') )

您也可以在这里检查:https://github.com/ponty/pyscreenshot以获取另一个“截屏”工具。

© www.soinside.com 2019 - 2024. All rights reserved.