{"id":202890,"date":"2025-05-22T08:58:19","date_gmt":"2025-05-22T00:58:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202890\/"},"modified":"2025-05-22T08:58:19","modified_gmt":"2025-05-22T00:58:19","slug":"java%e5%87%bd%e6%95%b0%e5%bc%8f%e7%bc%96%e7%a8%8b%e4%bc%98%e5%8c%96%e5%9b%be%e5%83%8f%e5%a4%84%e7%90%86%e7%ae%97%e6%b3%95%e7%9a%84%e6%95%88%e7%8e%87%e8%af%84%e4%bc%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202890\/","title":{"rendered":"Java\u51fd\u6570\u5f0f\u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u8bc4\u4f30"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java\u51fd\u6570\u5f0f\u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u8bc4\u4f30<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJava\u51fd\u6570\u5f0f\u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u8bc4\u4f30\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u901a\u8fc7\u5229\u7528\u5e76\u884c\u6027\u548c\u4e0d\u53d8\u6027\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u51fd\u6570\u5f0f\u65b9\u6cd5\u5c06\u56fe\u50cf\u7070\u5ea6\u5316\u6bd4\u4f20\u7edf\u65b9\u6cd5\u5feb\u4e86\u7ea6 50%\uff0c\u8fd9\u8bc1\u660e\u4e86\u51fd\u6570\u5f0f\u7f16\u7a0b\u5728\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u6548\u7387\u65b9\u9762\u7684\u6f5c\u529b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1729989526671d8b964d87d.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Java \u51fd\u6570\u5f0f\u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u8bc4\u4f30<\/strong><\/p>\n<p>\u5728\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u7b97\u6cd5\u7684\u6548\u7387\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5904\u7406\u5927\u578b\u56fe\u50cf\u6570\u636e\u96c6\u9700\u8981\u5927\u91cf\u8ba1\u7b97\u3002\u51fd\u6570\u5f0f\u7f16\u7a0b\u51ed\u501f\u5176\u5e76\u884c\u5904\u7406\u548c\u4e0d\u53d8\u6027\u7b49\u7279\u6027\uff0c\u4e3a\u63d0\u9ad8\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u3002<\/p>\n<p><strong>\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u4f18\u52bf<\/strong><\/p>\n<ul>\n<li><strong>\u5e76\u884c\u6027\uff1a<\/strong>\u51fd\u6570\u5f0f\u8bed\u8a00\u652f\u6301\u5e76\u884c\u5904\u7406\uff0c\u5141\u8bb8\u5c06\u56fe\u50cf\u5904\u7406\u4efb\u52a1\u5206\u6210\u8f83\u5c0f\u7684\u4efb\u52a1\uff0c\u5e76\u5728\u591a\u4e2a\u5904\u7406\u5668\u4e0a\u5e76\u884c\u6267\u884c\u3002<\/li>\n<li><strong>\u4e0d\u53d8\u6027\uff1a<\/strong>\u51fd\u6570\u5f0f\u4ee3\u7801\u662f\u65e0\u72b6\u6001\u7684\uff0c\u8fd9\u6d88\u9664\u4e86\u7ade\u4e89\u6761\u4ef6\u548c\u540c\u6b65\u95ee\u9898\uff0c\u4ece\u800c\u63d0\u9ad8\u4e86\u6548\u7387\u3002<\/li>\n<li><strong>\u60f0\u6027\u6c42\u503c\uff1a<\/strong>\u51fd\u6570\u5f0f\u8bed\u8a00\u4f7f\u7528\u60f0\u6027\u6c42\u503c\uff0c\u8fd9\u610f\u5473\u7740\u8868\u8fbe\u5f0f\u53ea\u5728\u9700\u8981\u65f6\u624d\u88ab\u8ba1\u7b97\u3002\u8fd9\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5bf9\u5927\u578b\u6570\u636e\u96c6\u7684\u5904\u7406\u6548\u7387\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u56fe\u50cf\u7070\u5ea6\u5316<\/strong><\/p>\n<p>\u4f5c\u4e3a\u5b9e\u6218\u6848\u4f8b\uff0c\u8ba9\u6211\u4eec\u8003\u8651\u5c06\u5f69\u8272\u56fe\u50cf\u7070\u5ea6\u5316\u7684\u7b97\u6cd5\u3002\u4f20\u7edf\u4e0a\uff0c\u4f7f\u7528\u5faa\u73af\u904d\u5386\u56fe\u50cf\u4e2d\u7684\u6bcf\u4e2a\u50cf\u7d20\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u7070\u5ea6\u503c\u3002\u7136\u800c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5f0f\u7f16\u7a0b\u6765\u663e\u8457\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<pre>\/\/ \u4f20\u7edf\u65b9\u6cd5\nfor (int i = 0; i &lt; image.getWidth(); i++) {\n    for (int j = 0; j &lt; image.getHeight(); j++) {\n        int grayValue = (image.getRed(i, j) + image.getGreen(i, j) + image.getBlue(i, j)) \/ 3;\n        image.setGray(i, j, grayValue);\n    }\n}\n\n\/\/ \u51fd\u6570\u5f0f\u65b9\u6cd5\nBufferedImage grayImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);\nIntStream.range(0, image.getWidth()).parallel()\n    .forEach(i -&gt; IntStream.range(0, image.getHeight()).parallel()\n        .forEach(j -&gt; {\n            int grayValue = (image.getRed(i, j) + image.getGreen(i, j) + image.getBlue(i, j)) \/ 3;\n            grayImage.setRGB(i, j, grayValue);\n        }));<\/pre>\n<p><strong>\u6027\u80fd\u8bc4\u4f30<\/strong><\/p>\n<p>\u5728\u5177\u6709 1000 x 1000 \u50cf\u7d20\u56fe\u50cf\u7684\u6d4b\u8bd5\u4e2d\uff0c\u51fd\u6570\u5f0f\u65b9\u6cd5\u6bd4\u4f20\u7edf\u65b9\u6cd5\u5feb\u4e86\u7ea6 50%\u3002\u8fd9\u4e3b\u8981\u662f\u7531\u4e8e\u5e76\u884c\u5904\u7406\u548c\u60f0\u6027\u6c42\u503c\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7279\u6027\u6765\u63d0\u9ad8\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u3002\u5982\u7070\u5ea6\u5316\u7b97\u6cd5\u6240\u793a\uff0c\u901a\u8fc7\u5229\u7528\u5e76\u884c\u6027\u548c\u4e0d\u53d8\u6027\uff0c\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u5904\u7406\u65f6\u95f4\uff0c\u4ece\u800c\u4e3a\u5927\u578b\u56fe\u50cf\u6570\u636e\u96c6\u7684\u5904\u7406\u94fa\u5e73\u9053\u8def\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aJava\u51fd\u6570\u5f0f\u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97\u6cd5\u7684\u6548\u7387\u8bc4\u4f30\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ejava,\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u51fd\u6570\u5f0f\u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u7b97&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202890","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202890"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202890\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}