{"id":657,"date":"2014-07-20T10:06:46","date_gmt":"2014-07-20T10:06:46","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=657"},"modified":"2014-07-20T10:06:46","modified_gmt":"2014-07-20T10:06:46","slug":"python%e6%88%aa%e5%b1%8f%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/657.html","title":{"rendered":"Python\u622a\u5c4f\u51fd\u6570"},"content":{"rendered":"<p>\u4e4b\u524d\u5c31\u4e00\u76f4\u60f3\u4e86\u89e3\u4e00\u4e0b\u5404\u79cd\u8bed\u8a00\u5982\u4f55\u5b9e\u73b0\u622a\u5c4f\/\u56fe\u50cf\u5904\u7406\u7684\u529f\u80fd\uff0c\u4f46\u4e00\u76f4\u6ca1\u6709\u627e\u5230\u5408\u9002\u7684\u5207\u5165\u70b9\uff0c\u8fd9\u6b21\u78b0\u5230\u4e86\u4e2aPython\u7684\u622a\u5c4f\u529f\u80fd\uff08Windows\u7cfb\u7edf\uff09\u7684\u4ee3\u7801\uff0c\u5b66\u4e60\/\u4fee\u6539\u4e86\u4e00\u4e0b\uff0c\u7528\u9014\u8fd8\u662f\u6bd4\u8f83\u591a\u7684(\u2606_\u2606)\/~~<\/p>\n<pre class=\"lang:default decode:true \">#!\/usr\/bin\/env python\n# -*- coding: utf-8 -*-\nfrom PIL import Image\nimport time, os, win32gui, win32ui, win32con, win32api\n\ndef window_capture(dpath):\n    '''\n\t\u622a\u5c4f\u51fd\u6570\uff0c\u8c03\u7528\u65b9\u6cd5window_capture('D:\\photos2\\')\uff0c\u53c2\u6570\u4e3a\u6307\u5b9a\u4fdd\u5b58\u7684\u76ee\u5f55\n\t\u8fd4\u56de\u56fe\u7247\u6587\u4ef6\u540d\uff0c\u6587\u4ef6\u540d\u683c\u5f0f\uff1a\u65e5\u671f.jpg\t\u5982\uff1a2009328224853.jpg\n    '''\n    hwnd = 0\n    hwndDC = win32gui.GetWindowDC(hwnd)\n    mfcDC=win32ui.CreateDCFromHandle(hwndDC)\n    saveDC=mfcDC.CreateCompatibleDC()\n    saveBitMap = win32ui.CreateBitmap()\n    MoniterDev=win32api.EnumDisplayMonitors(None,None)\n    w = MoniterDev[0][2][2]\n    h = MoniterDev[0][2][3]\n    #print w,h\t#\u56fe\u7247\u5927\u5c0f\n    saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)\n    saveDC.SelectObject(saveBitMap)\n    saveDC.BitBlt((0,0),(w, h) , mfcDC, (0,0), win32con.SRCCOPY)\n    cc=time.gmtime()\n    bmpname=str(cc[0])+str(cc[1])+str(cc[2])+str(cc[3]+8)+str(cc[4])+str(cc[5])+'.bmp'\n    saveBitMap.SaveBitmapFile(saveDC, bmpname)\n    Image.open(bmpname).save(bmpname[:-4]+\".jpg\")\n    os.remove(bmpname)\t# *.bmp is too big, so we convert it to jpg format\n    jpgname=bmpname[:-4]+'.jpg'\n    djpgname=dpath+jpgname\n    copy_command = \"move %s %s\" % (jpgname, djpgname)\n    os.popen(copy_command)\n    return bmpname[:-4]+'.jpg'\n\n#\u8c03\u7528\u622a\u5c4f\u51fd\u6570\n# window_capture('D:\\photos2\\')\npath = os.path.normcase(\"D:\/photos2\/\")\nwindow_capture(path)<\/pre>\n<p>\u53c2\u8003\u7f51\u5740\uff1a<\/p>\n<p><a href=\"http:\/\/OutOfMemory.cn\/\" target=\"_blank\">OutOfMemory<\/a><\/p>\n<p><a href=\"http:\/\/hongqn.livejournal.com\/13175.html\" target=\"_blank\">Python\u9677\u9631\uff1araw string<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5c31\u4e00\u76f4\u60f3\u4e86\u89e3\u4e00\u4e0b\u5404\u79cd\u8bed\u8a00\u5982\u4f55\u5b9e\u73b0\u622a\u5c4f\/\u56fe\u50cf\u5904\u7406\u7684\u529f\u80fd\uff0c\u4f46\u4e00\u76f4\u6ca1\u6709\u627e\u5230\u5408\u9002\u7684\u5207\u5165\u70b9\uff0c\u8fd9\u6b21\u78b0\u5230\u4e86\u4e2aPython [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,20],"tags":[8],"class_list":["post-657","post","type-post","status-publish","format-standard","hentry","category-programing","category-windows","tag-python"],"views":2821,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=657"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/657\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}