抓取屏幕(截图)的问题

抓取屏幕(截图)的问题

这是一个视频演示该问题。

每当我尝试截取屏幕截图时,我截取的图片与我认为截取的图片不同(除非按下键时使用 ubuntu 的截屏功能)。这个问题与快门没有特别关系(来自视频),但我用 python 编写的屏幕截图程序也演示了相同的行为。截取屏幕截图的代码示例如下:

def grab_screenshot():
    """ Grabs a screenshot of the active window and saves it as a png with the current time """
    root = gtk.gdk.screen_get_default()

    if root.supports_net_wm_hint("_NET_ACTIVE_WINDOW") and root.supports_net_wm_hint("_NET_WM_WINDOW_TYPE"):
        print "Grabbing active window"
        active = root.get_active_window()

        # Comment these two lines if you dont want to enable screenshotting of the entire desktop
        # instead of just the active window.
#        if active.property_get("_NET_WM_WINDOW_TYPE")[-1][0] == '_NET_WM_WINDOW_TYPE_DESKTOP':
#            return "FAIL"

        # Calculate the size of the wm decorations
        relativex, relativey, winw, winh, d = active.get_geometry() 
        w = winw + (relativex*2)
        h = winh + (relativey+relativex)

        # Calculate the position of where the wm decorations start (not the window itself)
        screenposx, screenposy = active.get_root_origin()
        print "screen posx: %d" % screenposx
        print "screen posy: %d" % screenposy

        # Take the screenshot
        screenshot = gtk.gdk.Pixbuf.get_from_drawable(gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h),
                                                      gtk.gdk.get_default_root_window(),
                                                      gtk.gdk.colormap_get_system(),
                                                      screenposx, screenposy, 0, 0, w, h)
    else:
        window = gtk.gdk.get_default_root_window()
        size = window.get_size()
        print "The size of the window is %d x %d" % size
        pixel_buffer = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, size[0], size[1])
        screenshot = pixel_buffer.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0, size[0], size[1])

    if (screenshot != None):
        timeNow = time.time()
        fileName = "screenshot_%d.png" %timeNow
        screenshot.save(fileName, "png")

        print "Screenshot saved to " + fileName
    else:
        print "Unable to get the screenshot."
        fileName = "FAIL"

    return fileName

我猜这是 gtk 的问题?我尝试在 compiz 中勾选 gtk 加载实用程序,但似乎没有任何帮助。

相关内容