{"id":1120950,"date":"2025-01-08T19:03:52","date_gmt":"2025-01-08T11:03:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1120950.html"},"modified":"2025-01-08T19:03:55","modified_gmt":"2025-01-08T11:03:55","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87python%e8%8e%b7%e5%8f%96%e7%94%b5%e8%84%91%e6%a1%8c%e9%9d%a2%e5%9b%be%e5%83%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1120950.html","title":{"rendered":"\u5982\u4f55\u901a\u8fc7python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083407\/06e9a3d0-a3fe-42dc-bdf3-c389e5b01e8b.webp\" alt=\"\u5982\u4f55\u901a\u8fc7python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u901a\u8fc7Python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7Python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf\u7684\u6838\u5fc3\u65b9\u6cd5\u5305\u62ec\uff1a<strong>\u4f7f\u7528Pillow\u5e93\u622a\u5c4f\u3001\u5229\u7528PyAutoGUI\u5e93\u622a\u5c4f\u3001\u4f7f\u7528mss\u5e93\u8fdb\u884c\u9ad8\u6548\u622a\u5c4f<\/strong>\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u5176\u4e2d\uff0c<strong>\u4f7f\u7528mss\u5e93\u8fdb\u884c\u9ad8\u6548\u622a\u5c4f<\/strong>\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u901f\u5ea6\u5feb\u4e14\u5360\u7528\u8d44\u6e90\u5c11\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528mss\u5e93\u8fdb\u884c\u9ad8\u6548\u622a\u5c4f<\/strong>\uff1amss\u5e93\u662fPython\u4e2d\u4e00\u4e2a\u7528\u4e8e\u622a\u5c4f\u7684\u9ad8\u6548\u5de5\u5177\uff0c\u5b83\u4e0d\u4ec5\u652f\u6301\u591a\u5e73\u53f0\uff08Windows, macOS, \u548c Linux\uff09\uff0c\u800c\u4e14\u5728\u622a\u5c4f\u901f\u5ea6\u4e0a\u8868\u73b0\u4f18\u5f02\u3002\u76f8\u6bd4\u4e8e\u5176\u4ed6\u622a\u5c4f\u65b9\u6cd5\uff0cmss\u5e93\u53ef\u4ee5\u5728\u77ed\u65f6\u95f4\u5185\u6355\u83b7\u9ad8\u5206\u8fa8\u7387\u7684\u56fe\u50cf\uff0c\u5e76\u4e14\u8d44\u6e90\u5360\u7528\u8f83\u5c11\uff0c\u662f\u5904\u7406\u5b9e\u65f6\u56fe\u50cf\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001PILLOW\u5e93\u622a\u5c4f<\/h2>\n<\/p>\n<p><p>Pillow\u5e93\uff08PIL\uff09\u662fPython\u56fe\u50cf\u5904\u7406\u5e93\u7684\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5904\u7406\u56fe\u50cf\u7684\u529f\u80fd\uff0c\u5305\u62ec\u622a\u5c4f\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Pillow\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86Pillow\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528Pillow\u5e93\u622a\u5c4f<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Pillow\u5e93\u622a\u5c4f\u975e\u5e38\u7b80\u5355\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import ImageGrab<\/p>\n<h2><strong>\u622a\u53d6\u6574\u4e2a\u5c4f\u5e55<\/strong><\/h2>\n<p>screenshot = ImageGrab.grab()<\/p>\n<h2><strong>\u4fdd\u5b58\u622a\u56fe<\/strong><\/h2>\n<p>screenshot.save(&quot;screenshot.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u5904\u7406\u548c\u4fdd\u5b58\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Pillow\u5e93\u622a\u5c4f\u540e\u7684\u56fe\u50cf\u662f\u4e00\u4e2aPIL Image\u5bf9\u8c61\uff0c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u5404\u79cd\u5904\u7406\uff0c\u4f8b\u5982\u88c1\u526a\u3001\u7f29\u653e\u3001\u6dfb\u52a0\u6ee4\u955c\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&quot;screenshot.png&quot;)<\/p>\n<h2><strong>\u88c1\u526a\u56fe\u50cf<\/strong><\/h2>\n<p>cropped_image = image.crop((100, 100, 400, 400))<\/p>\n<h2><strong>\u4fdd\u5b58\u88c1\u526a\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cropped_image.save(&quot;cropped_screenshot.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001PYAUTOGUI\u5e93\u622a\u5c4f<\/h2>\n<\/p>\n<p><p>PyAutoGUI\u662f\u4e00\u4e2a\u7528\u4e8e\u81ea\u52a8\u5316\u63a7\u5236\u952e\u76d8\u548c\u9f20\u6807\u64cd\u4f5c\u7684\u5e93\uff0c\u540c\u65f6\u4e5f\u652f\u6301\u622a\u5c4f\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5PyAutoGUI\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86PyAutoGUI\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyautogui<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528PyAutoGUI\u5e93\u622a\u5c4f<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528PyAutoGUI\u5e93\u622a\u5c4f\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyautogui<\/p>\n<h2><strong>\u622a\u53d6\u6574\u4e2a\u5c4f\u5e55<\/strong><\/h2>\n<p>screenshot = pyautogui.screenshot()<\/p>\n<h2><strong>\u4fdd\u5b58\u622a\u56fe<\/strong><\/h2>\n<p>screenshot.save(&quot;screenshot.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u83b7\u53d6\u6307\u5b9a\u533a\u57df\u7684\u622a\u56fe<\/h3>\n<\/p>\n<p><p>PyAutoGUI\u5e93\u8fd8\u652f\u6301\u622a\u53d6\u5c4f\u5e55\u7684\u6307\u5b9a\u533a\u57df\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyautogui<\/p>\n<h2><strong>\u622a\u53d6\u5c4f\u5e55\u7684\u6307\u5b9a\u533a\u57df (\u5de6\u4e0a\u89d2x, \u5de6\u4e0a\u89d2y, \u5bbd\u5ea6, \u9ad8\u5ea6)<\/strong><\/h2>\n<p>screenshot = pyautogui.screenshot(region=(100, 100, 300, 300))<\/p>\n<h2><strong>\u4fdd\u5b58\u622a\u56fe<\/strong><\/h2>\n<p>screenshot.save(&quot;region_screenshot.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001MSS\u5e93\u8fdb\u884c\u9ad8\u6548\u622a\u5c4f<\/h2>\n<\/p>\n<p><p>MSS\u5e93\u662f\u4e00\u4e2a\u7528\u4e8e\u622a\u5c4f\u7684\u9ad8\u6548\u5de5\u5177\uff0c\u652f\u6301\u591a\u5e73\u53f0\uff0c\u5e76\u4e14\u5728\u622a\u5c4f\u901f\u5ea6\u4e0a\u8868\u73b0\u4f18\u5f02\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5MSS\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86MSS\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install mss<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528MSS\u5e93\u622a\u5c4f<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528MSS\u5e93\u622a\u5c4f\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mss<\/p>\n<p>with mss.mss() as sct:<\/p>\n<p>    # \u83b7\u53d6\u4e3b\u5c4f\u5e55\u622a\u56fe<\/p>\n<p>    screenshot = sct.shot()<\/p>\n<h2><strong>\u9ed8\u8ba4\u4fdd\u5b58\u4e3a monitor-1.png<\/strong><\/h2>\n<p>print(f&quot;Screenshot saved as {screenshot}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u83b7\u53d6\u6307\u5b9a\u533a\u57df\u7684\u622a\u56fe<\/h3>\n<\/p>\n<p><p>MSS\u5e93\u8fd8\u652f\u6301\u622a\u53d6\u5c4f\u5e55\u7684\u6307\u5b9a\u533a\u57df\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mss<\/p>\n<p>with mss.mss() as sct:<\/p>\n<p>    # \u5b9a\u4e49\u622a\u53d6\u533a\u57df<\/p>\n<p>    monitor = {&quot;top&quot;: 100, &quot;left&quot;: 100, &quot;width&quot;: 300, &quot;height&quot;: 300}<\/p>\n<p>    # \u83b7\u53d6\u6307\u5b9a\u533a\u57df\u622a\u56fe<\/p>\n<p>    screenshot = sct.grab(monitor)<\/p>\n<p>    # \u4fdd\u5b58\u622a\u56fe<\/p>\n<p>    mss.tools.to_png(screenshot.rgb, screenshot.size, output=&quot;region_screenshot.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u7efc\u5408\u5e94\u7528\u4e0e\u6027\u80fd\u5bf9\u6bd4<\/h2>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u622a\u5c4f\u65b9\u6cd5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u5bf9\u4e09\u79cd\u65b9\u6cd5\u7684\u7efc\u5408\u5e94\u7528\u548c\u6027\u80fd\u5bf9\u6bd4\u3002<\/p>\n<\/p>\n<p><h3>1\u3001Pillow\u5e93\u7684\u4f18\u7f3a\u70b9<\/h3>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u529f\u80fd\u4e30\u5bcc\uff0c\u652f\u6301\u5bf9\u56fe\u50cf\u8fdb\u884c\u5404\u79cd\u5904\u7406\u3002<\/li>\n<li>\u6613\u4e8e\u4f7f\u7528\uff0cAPI\u8bbe\u8ba1\u7b80\u6d01\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u622a\u5c4f\u901f\u5ea6\u76f8\u5bf9\u8f83\u6162\u3002<\/li>\n<li>\u8d44\u6e90\u5360\u7528\u8f83\u591a\uff0c\u4e0d\u9002\u5408\u5b9e\u65f6\u56fe\u50cf\u5904\u7406\u3002<\/li>\n<\/ul>\n<p><h3>2\u3001PyAutoGUI\u5e93\u7684\u4f18\u7f3a\u70b9<\/h3>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u652f\u6301\u81ea\u52a8\u5316\u63a7\u5236\u952e\u76d8\u548c\u9f20\u6807\u64cd\u4f5c\uff0c\u9002\u7528\u4e8e\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002<\/li>\n<li>\u6613\u4e8e\u4f7f\u7528\uff0cAPI\u8bbe\u8ba1\u7b80\u6d01\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u622a\u5c4f\u901f\u5ea6\u76f8\u5bf9\u8f83\u6162\u3002<\/li>\n<li>\u8d44\u6e90\u5360\u7528\u8f83\u591a\uff0c\u4e0d\u9002\u5408\u9ad8\u9891\u7387\u622a\u5c4f\u3002<\/li>\n<\/ul>\n<p><h3>3\u3001MSS\u5e93\u7684\u4f18\u7f3a\u70b9<\/h3>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u622a\u5c4f\u901f\u5ea6\u5feb\uff0c\u9002\u7528\u4e8e\u5b9e\u65f6\u56fe\u50cf\u5904\u7406\u3002<\/li>\n<li>\u8d44\u6e90\u5360\u7528\u5c11\uff0c\u6027\u80fd\u4f18\u5f02\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u529f\u80fd\u76f8\u5bf9\u5355\u4e00\uff0c\u4e3b\u8981\u7528\u4e8e\u622a\u5c4f\uff0c\u4e0d\u652f\u6301\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u3002<\/li>\n<\/ul>\n<p><h3>4\u3001\u6027\u80fd\u5bf9\u6bd4<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u4e09\u79cd\u622a\u5c4f\u65b9\u6cd5\u7684\u6027\u80fd\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6027\u80fd\u6d4b\u8bd5\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>from PIL import ImageGrab<\/p>\n<p>import pyautogui<\/p>\n<p>import mss<\/p>\n<p>def test_pillow():<\/p>\n<p>    start = time.time()<\/p>\n<p>    screenshot = ImageGrab.grab()<\/p>\n<p>    end = time.time()<\/p>\n<p>    print(f&quot;Pillow\u622a\u5c4f\u65f6\u95f4: {end - start}\u79d2&quot;)<\/p>\n<p>def test_pyautogui():<\/p>\n<p>    start = time.time()<\/p>\n<p>    screenshot = pyautogui.screenshot()<\/p>\n<p>    end = time.time()<\/p>\n<p>    print(f&quot;PyAutoGUI\u622a\u5c4f\u65f6\u95f4: {end - start}\u79d2&quot;)<\/p>\n<p>def test_mss():<\/p>\n<p>    with mss.mss() as sct:<\/p>\n<p>        start = time.time()<\/p>\n<p>        screenshot = sct.shot()<\/p>\n<p>        end = time.time()<\/p>\n<p>        print(f&quot;MSS\u622a\u5c4f\u65f6\u95f4: {end - start}\u79d2&quot;)<\/p>\n<p>test_pillow()<\/p>\n<p>test_pyautogui()<\/p>\n<p>test_mss()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u53ef\u4ee5\u5f97\u5230\u4e09\u79cd\u622a\u5c4f\u65b9\u6cd5\u7684\u65f6\u95f4\u5bf9\u6bd4\u7ed3\u679c\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0cMSS\u5e93\u7684\u622a\u5c4f\u901f\u5ea6\u6700\u5feb\uff0c\u5176\u6b21\u662fPyAutoGUI\u5e93\uff0c\u6700\u540e\u662fPillow\u5e93\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u622a\u5c4f\u65b9\u6cd5\u975e\u5e38\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u53ca\u5176\u63a8\u8350\u7684\u622a\u5c4f\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b9e\u65f6\u56fe\u50cf\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u9700\u8981\u5b9e\u65f6\u5904\u7406\u56fe\u50cf\u7684\u5e94\u7528\u4e2d\uff0c\u4f8b\u5982\u89c6\u9891\u6d41\u5904\u7406\u3001\u6e38\u620f\u753b\u9762\u5206\u6790\u7b49\uff0c\u63a8\u8350\u4f7f\u7528MSS\u5e93\u8fdb\u884c\u622a\u5c4f\u3002MSS\u5e93\u7684\u9ad8\u6548\u622a\u5c4f\u6027\u80fd\u53ef\u4ee5\u4fdd\u8bc1\u56fe\u50cf\u5904\u7406\u7684\u5b9e\u65f6\u6027\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5<\/h3>\n<\/p>\n<p><p>\u5728\u81ea\u52a8\u5316\u6d4b\u8bd5\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u63a7\u5236\u952e\u76d8\u548c\u9f20\u6807\u64cd\u4f5c\uff0c\u540c\u65f6\u8fdb\u884c\u622a\u5c4f\u3002\u6b64\u65f6\uff0c\u63a8\u8350\u4f7f\u7528PyAutoGUI\u5e93\u3002PyAutoGUI\u5e93\u4e0d\u4ec5\u652f\u6301\u622a\u5c4f\uff0c\u8fd8\u652f\u6301\u81ea\u52a8\u5316\u63a7\u5236\u952e\u76d8\u548c\u9f20\u6807\u64cd\u4f5c\uff0c\u9002\u7528\u4e8e\u81ea\u52a8\u5316\u6d4b\u8bd5\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u56fe\u50cf\u5904\u7406\u548c\u7f16\u8f91<\/h3>\n<\/p>\n<p><p>\u5728\u9700\u8981\u5bf9\u622a\u5c4f\u56fe\u50cf\u8fdb\u884c\u5904\u7406\u548c\u7f16\u8f91\u7684\u5e94\u7528\u4e2d\uff0c\u4f8b\u5982\u56fe\u50cf\u88c1\u526a\u3001\u6dfb\u52a0\u6ee4\u955c\u7b49\uff0c\u63a8\u8350\u4f7f\u7528Pillow\u5e93\u3002Pillow\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u6ee1\u8db3\u5404\u79cd\u56fe\u50cf\u5904\u7406\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u901a\u8fc7Python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5e38\u7528\u7684\u5305\u62ec\u4f7f\u7528Pillow\u5e93\u3001PyAutoGUI\u5e93\u548cMSS\u5e93\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u622a\u5c4f\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u548c\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528MSS\u5e93\u8fdb\u884c\u9ad8\u6548\u622a\u5c4f<\/strong>\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u901f\u5ea6\u5feb\u4e14\u5360\u7528\u8d44\u6e90\u5c11\uff0c\u9002\u7528\u4e8e\u5b9e\u65f6\u56fe\u50cf\u5904\u7406\u3002<strong>\u5229\u7528PyAutoGUI\u5e93\u622a\u5c4f<\/strong>\u9002\u7528\u4e8e\u81ea\u52a8\u5316\u6d4b\u8bd5\u573a\u666f\uff0c\u800c<strong>\u4f7f\u7528Pillow\u5e93\u622a\u5c4f<\/strong>\u5219\u9002\u7528\u4e8e\u9700\u8981\u5bf9\u56fe\u50cf\u8fdb\u884c\u590d\u6742\u5904\u7406\u548c\u7f16\u8f91\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u672c\u6587\u63d0\u4f9b\u7684\u5185\u5bb9\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u622a\u5c4f\u6280\u672f\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u83b7\u53d6\u684c\u9762\u56fe\u50cf\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7Python\u4e2d\u7684\u51e0\u4e2a\u5e93\u6765\u6355\u6349\u684c\u9762\u56fe\u50cf\u3002\u6700\u5e38\u7528\u7684\u662f<code>pyautogui<\/code>\u548c<code>Pillow<\/code>\u3002\u4f7f\u7528<code>pyautogui.screenshot()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u5f53\u524d\u684c\u9762\u7684\u5feb\u7167\u3002\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86\u8fd9\u4e9b\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install pyautogui pillow<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u83b7\u53d6\u7684\u684c\u9762\u56fe\u50cf\u53ef\u4ee5\u4fdd\u5b58\u4e3a\u54ea\u4e9b\u683c\u5f0f\uff1f<\/strong><br \/>\u4f7f\u7528<code>Pillow<\/code>\u5e93\u5904\u7406\u56fe\u50cf\u65f6\uff0c\u60a8\u53ef\u4ee5\u5c06\u684c\u9762\u56fe\u50cf\u4fdd\u5b58\u4e3a\u591a\u79cd\u683c\u5f0f\uff0c\u5305\u62ecJPEG\u3001PNG\u548cBMP\u7b49\u3002\u53ea\u9700\u5728\u4fdd\u5b58\u56fe\u50cf\u65f6\u6307\u5b9a\u76f8\u5e94\u7684\u6587\u4ef6\u6269\u5c55\u540d\uff0c\u4f8b\u5982<code>.png<\/code>\u6216<code>.jpg<\/code>\uff0c\u5373\u53ef\u5b8c\u6210\u683c\u5f0f\u8f6c\u6362\u3002<\/p>\n<p><strong>\u5728\u83b7\u53d6\u684c\u9762\u56fe\u50cf\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u6355\u6349\u684c\u9762\u56fe\u50cf\u65f6\uff0c\u786e\u4fdd\u60a8\u7684\u5c4f\u5e55\u5206\u8fa8\u7387\u8bbe\u7f6e\u6b63\u786e\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u5f71\u54cd\u6355\u6349\u5230\u7684\u56fe\u50cf\u8d28\u91cf\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u6ca1\u6709\u5176\u4ed6\u7a97\u53e3\u906e\u6321\u5c4f\u5e55\u7684\u5185\u5bb9\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6e05\u6670\u7684\u56fe\u50cf\u3002\u5982\u679c\u9700\u8981\u5728\u8fd0\u884c\u7a0b\u5e8f\u65f6\u907f\u514d\u5e72\u6270\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u7a0b\u5e8f\u653e\u5728\u540e\u53f0\u6267\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u901a\u8fc7Python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf \u901a\u8fc7Python\u83b7\u53d6\u7535\u8111\u684c\u9762\u56fe\u50cf\u7684\u6838\u5fc3\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Pillow\u5e93\u622a\u5c4f\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1120962,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120950"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1120950"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120950\/revisions"}],"predecessor-version":[{"id":1120967,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120950\/revisions\/1120967"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1120962"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1120950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1120950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1120950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}