{"id":202714,"date":"2025-05-22T09:25:04","date_gmt":"2025-05-22T01:25:04","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202714\/"},"modified":"2025-05-22T09:25:04","modified_gmt":"2025-05-22T01:25:04","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8%e5%87%bd%e6%95%b0%e5%bc%8fjava%e7%bc%96%e7%a8%8b%e6%94%b9%e5%96%84%e5%9b%be%e5%83%8f%e5%a4%84%e7%90%86%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202714\/","title":{"rendered":"\u5982\u4f55\u5229\u7528\u51fd\u6570\u5f0fJava\u7f16\u7a0b\u6539\u5584\u56fe\u50cf\u5904\u7406\u6027\u80fd"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5229\u7528\u51fd\u6570\u5f0fJava\u7f16\u7a0b\u6539\u5584\u56fe\u50cf\u5904\u7406\u6027\u80fd<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u5229\u7528\u51fd\u6570\u5f0fJava\u7f16\u7a0b\u6539\u5584\u56fe\u50cf\u5904\u7406\u6027\u80fd\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p>\u51fd\u6570\u5f0f Java \u7f16\u7a0b\u901a\u8fc7\u5f3a\u8c03\u4e0d\u53ef\u53d8\u6570\u636e\u548c\u51fd\u6570\u7ec4\u5408\uff0c\u53ef\u4ee5\u4f18\u5316\u56fe\u50cf\u5904\u7406\u6027\u80fd\uff0c\u5177\u4f53\u4f53\u73b0\u5728\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a\u4e0d\u53ef\u53d8\u6570\u636e\u6d88\u9664\u4e86\u6f5c\u5728\u7684\u526f\u4f5c\u7528\u62c5\u5fe7\uff0c\u7b80\u5316\u4e86\u5e76\u884c\u5904\u7406\u3002\u51fd\u6570\u7ec4\u5408\u5141\u8bb8\u901a\u8fc7\u7ec4\u5408\u73b0\u6709\u51fd\u6570\u521b\u5efa\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u7b80\u5316\u4e86\u4ee3\u7801\u7f16\u5199\u3002\u6570\u636e\u4e0d\u53ef\u53d8\u6027\u4f7f\u5e76\u884c\u5904\u7406\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\uff0c\u56e0\u4e3a\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u5b89\u5168\u5730\u64cd\u4f5c\u76f8\u540c\u7684\u6570\u636e\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729935947671cba4b39e90.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5229\u7528\u51fd\u6570\u5f0f Java \u7f16\u7a0b\u4f18\u5316\u56fe\u50cf\u5904\u7406\u6027\u80fd<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u662f\u4e00\u79cd\u7f16\u7a0b\u8303\u4f8b\uff0c\u5b83\u5f3a\u8c03\u4e0d\u53ef\u53d8\u6570\u636e\u548c\u51fd\u6570\u7684\u7ec4\u5408\u3002\u5728\u56fe\u50cf\u5904\u7406\u4e2d\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u7b80\u6d01\u3001\u9ad8\u6548\u7684\u89e3\u51b3\u65b9\u6848\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<p><strong>\u4e0d\u53ef\u53d8\u6570\u636e<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\u7684\u53d8\u91cf\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u88ab\u4fee\u6539\u3002\u8fd9\u6d88\u9664\u4e86\u5bf9\u4fee\u6539\u53d8\u91cf\u6f5c\u5728\u526f\u4f5c\u7528\u7684\u62c5\u5fe7\uff0c\u5e76\u7b80\u5316\u4e86\u5e76\u884c\u5904\u7406\u3002<\/p>\n<pre>\/\/ \u53ef\u53d8\u56fe\u50cf\u6570\u636e\nBufferedImage mutableImage = new BufferedImage(...);\nmutableImage.setRGB(x, y, color);\n\n\/\/ \u4e0d\u53ef\u53d8\u56fe\u50cf\u6570\u636e\nImmutableBufferedImage immutableImage = ImmutableBufferedImage.of(...)\nImmutableBufferedImage newImage = immutableImage.withRGB(x, y, color);<\/pre>\n<p><strong>\u51fd\u6570\u7ec4\u5408<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u4f7f\u7528\u51fd\u6570\u7ec4\u5408\u6765\u521b\u5efa\u65b0\u7684\u51fd\u6570\u3002\u901a\u8fc7\u5c06\u73b0\u6709\u51fd\u6570\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u800c\u65e0\u9700\u7f16\u5199\u5927\u91cf\u4ee3\u7801\u3002<\/p>\n<pre>\/\/ \u4fee\u6539\u50cf\u7d20\u7684\u4eae\u5ea6\u7684\u53ef\u53d8\u51fd\u6570\nUnaryOperator&lt;Color&gt; brightenFunction = color -&gt; color.brighter();\n\n\/\/ \u4fee\u6539\u50cf\u7d20\u5bf9\u6bd4\u5ea6\u7684\u53ef\u53d8\u51fd\u6570\nUnaryOperator&lt;Color&gt; contrastFunction = color -&gt; color.contrast(1.5f);\n\n\/\/ \u7ec4\u5408\u4e24\u4e2a\u51fd\u6570\uff0c\u521b\u5efa\u65b0\u7684\u4eae\u5ea6\u548c\u5bf9\u6bd4\u5ea6\u51fd\u6570\nFunction&lt;Color, Color&gt; brightnessContrastFunction =\n    brightenFunction.andThen(contrastFunction);<\/pre>\n<p><strong>\u5e76\u884c\u5904\u7406<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\u7684\u6570\u636e\u4e0d\u53ef\u53d8\u6027\u4f7f\u5e76\u884c\u5904\u7406\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\uff0c\u56e0\u4e3a\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u5b89\u5168\u5730\u64cd\u4f5c\u76f8\u540c\u7684\u6570\u636e\u3002<\/p>\n<pre>\/\/ \u4f7f\u7528\u63d0\u4f9b\u7684\u5e76\u884c\u6d41\u5904\u7406\u56fe\u50cf\u4e2d\u7684\u6bcf\u4e2a\u50cf\u7d20\nArrays.stream(image.getData()).parallel()\n    .map(brightnessContrastFunction)\n    .toArray();<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528\u51fd\u6570\u5f0f Java \u7f16\u7a0b\u4f18\u5316\u7684\u56fe\u50cf\u5904\u7406\u5b9e\u6218\u6848\u4f8b\uff1a<\/p>\n<ul>\n<li><strong>\u56fe\u50cf\u7f29\u653e<\/strong>\uff1a\u901a\u8fc7\u5c06\u56fe\u50cf\u5206\u6210\u8f83\u5c0f\u7684\u5757\uff0c\u7136\u540e\u5e76\u884c\u5904\u7406\u8fd9\u4e9b\u5757\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u56fe\u50cf\u7f29\u653e\u901f\u5ea6\u3002<\/li>\n<li><strong>\u56fe\u50cf\u6ee4\u6ce2<\/strong>\uff1a\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u7ec4\u5408\u521b\u5efa\u590d\u6742\u7684\u6ee4\u6ce2\u5668\uff0c\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u8981\u6c42\u8f7b\u677e\u5730\u5e94\u7528\u5404\u79cd\u6ee4\u6ce2\u5668\u6548\u679c\u3002<\/li>\n<li><strong>\u56fe\u50cf\u5408\u6210<\/strong>\uff1a\u901a\u8fc7\u4f7f\u7528\u4e0d\u53ef\u53d8\u6570\u636e\u548c\u51fd\u6570\u7ec4\u5408\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u591a\u4e2a\u56fe\u50cf\u5408\u6210\u5230\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf\u4e2d\uff0c\u800c\u65e0\u9700\u62c5\u5fc3\u526f\u4f5c\u7528\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u91c7\u7528\u51fd\u6570\u5f0f Java \u7f16\u7a0b\u8303\u4f8b\uff0c\u56fe\u50cf\u5904\u7406\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u83b7\u5f97\u66f4\u9ad8\u7684\u6027\u80fd\u548c\u4ee3\u7801\u7b80\u5316\uff0c\u4ece\u800c\u63d0\u9ad8\u5f00\u53d1\u4eba\u5458\u7684\u751f\u4ea7\u529b\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u80fd\u529b\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u5229\u7528\u51fd\u6570\u5f0fJava\u7f16\u7a0b\u6539\u5584\u56fe\u50cf\u5904\u7406\u6027\u80fd\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5229\u7528\u51fd\u6570\u5f0fJava\u7f16\u7a0b\u6539\u5584\u56fe&#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-202714","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202714","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=202714"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202714\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}