Use python win32gui for drawing

來源:互聯網
上載者:User

 

import win32gui<br />from re import match<br />def draw_line():<br /> print 'x1,y1,x2,y2?'<br /> s=raw_input()<br /> if match('/d+,/d+,/d+,/d+',s):<br /> x1,y1,x2,y2=s.split(',')<br /> x1=int(x1)<br /> y1=int(y1)<br /> x2=int(x2)<br /> y2=int(y2)<br /> hwnd=win32gui.WindowFromPoint((x1,y1))<br /> hdc=win32gui.GetDC(hwnd)<br /> x1c,y1c=win32gui.ScreenToClient(hwnd,(x1,y1))<br /> x2c,y2c=win32gui.ScreenToClient(hwnd,(x2,y2))<br /> win32gui.MoveToEx(hdc,x1c,y1c)<br /> win32gui.LineTo(hdc,x2c,y2c)<br /> win32gui.ReleaseDC(hwnd,hdc)<br /> main()<br />def draw_point():<br /> print 'x,y,color?'<br /> s=raw_input()<br /> if match('/d+,/d+,/d+',s):<br /> x,y,color=s.split(',')<br /> x=int(x)<br /> y=int(y)<br /> color=int(color)<br /> hwnd=win32gui.WindowFromPoint((x,y))<br /> hdc=win32gui.GetDC(hwnd)<br /> x1,y1=win32gui.ScreenToClient(hwnd,(x,y))<br /> win32gui.SetPixel(hdc,x1,y1,color)<br /> win32gui.ReleaseDC(hwnd,hdc)<br /> main()<br />def get_pixel_col():<br /> print 'x,y?'<br /> s=raw_input()<br /> if match('/d+,/d+',s):<br /> x,y=s.split(',')<br /> x=int(x)<br /> y=int(y)<br /> hwnd=win32gui.WindowFromPoint((x,y))<br /> hdc=win32gui.GetDC(hwnd)<br /> x1,y1=win32gui.ScreenToClient(hwnd,(x,y))<br /> color=win32gui.GetPixel(hdc,x1,y1)<br /> win32gui.ReleaseDC(hwnd,hdc)<br /> print color<br /> main()<br />def get_current_pos_info():<br /> x,y=win32gui.GetCursorPos()<br /> hwnd=win32gui.WindowFromPoint((x,y))<br /> hdc=win32gui.GetDC(hwnd)<br /> x1,y1=win32gui.ScreenToClient(hwnd,(x,y))<br /> print x,y,win32gui.GetPixel(hdc,x1,y1)<br /> win32gui.ReleaseDC(hwnd,hdc)<br /> main()<br />def main():<br /> print ('''l. draw line<br />p. draw point<br />g. get pixel color<br />c. get current mouse position's info''')<br /> s=raw_input()<br /> if s.lower()=='l':<br /> draw_line()<br /> if s.lower()=='p':<br /> draw_point()<br /> if s.lower()=='g':<br /> get_pixel_col()<br /> if s.lower()=='c':<br /> get_current_pos_info()<br />main() 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.