我需要在我的应用程序中绘制屏幕的某个区域...虽然我的代码工作正常,但速度非常慢......质量低劣需要20秒以上,质量最好需要30-40秒。 .. 有没有更快的方式做同样的...我希望它在最短的0.5秒内完成...
通过拍摄截图...我可以在5秒钟内完成...但我需要在0.5秒内完成......
xlib对我来说不是必需的......如果你能提出更快更好的建议,那就太棒了!class Window:
def __init__(self, display, msg):
self.display = display
self.msg = msg
self.screen = self.display.screen()
self.window = self.screen.root.create_window(
10, 10, 300, 300, 1,
self.screen.root_depth,
background_pixel=self.screen.white_pixel,
event_mask=X.ExposureMask | X.KeyPressMask,
)
self.colormap = self.screen.default_colormap
color = self.colormap.alloc_color(0, 0, 65535)
xor_color = color.pixel ^ 0xffffff
self.gc = self.window.create_gc(
line_width = 2,
line_style = X.LineSolid,
fill_style = X.FillOpaqueStippled,
fill_rule = X.WindingRule,
cap_style = X.CapButt,
join_style = X.JoinMiter,
foreground = xor_color,
background = self.screen.black_pixel,
function = X.GXxor,
graphics_exposures = False,
subwindow_mode = X.IncludeInferiors,
)
self.window.map()
def loop(self):
while True:
e = self.display.next_event()
if e.type == X.Expose:
i=10
j=10
h=10
k=10
skip=0
while j<121:
while i<121:
if skip==0:
o_x_image=self.screen.root.get_image(i, j, 1, 1, Xlib.X.ZPixmap, 0xffffffff)
o_pil_image_rgb = PIL.Image.fromstring("RGB", (1, 1), o_x_image.data, "raw", "BGRX")
b = PIL.ImageStat.Stat(o_pil_image_rgb).mean
b=map(int, b)
r=b[0]*255
g=b[1]*255
b=b[2]*255
color = self.colormap.alloc_color(r,g,b)
xor_color = color.pixel ^ 0xffffff
self.gc = self.window.create_gc(
foreground = xor_color,
function = X.GXxor
)
skip=1
#print "not skipping"
elif skip==1:
skip=0
#print "skipped"
self.window.point(self.gc,h,k)
h+=1
i+=1
j+=1
i=10
k+=1
h=10
elif e.type == X.KeyPress:
raise SystemExit