{"id":146,"date":"2017-05-12T16:00:00","date_gmt":"2017-05-12T08:00:00","guid":{"rendered":"https:\/\/cn1.club\/?p=146"},"modified":"2025-03-13T20:19:43","modified_gmt":"2025-03-13T12:19:43","slug":"%e9%aa%8c%e8%af%81%e7%a0%81-%e9%9a%8f%e6%9c%ba%e7%94%9f%e6%88%90%e5%ad%97%e5%ba%93%e5%8f%af%e8%87%aa%e5%ae%9a%e4%b9%89","status":"publish","type":"post","link":"http:\/\/cn1.club\/?p=146","title":{"rendered":"\u9a8c\u8bc1\u7801 \u968f\u673a\u751f\u6210,\u5b57\u5e93\u53ef\u81ea\u5b9a\u4e49"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >package com.itheima.controller;\n\nimport java.awt.Color;\nimport java.awt.Font;\nimport java.awt.Graphics;\nimport java.awt.image.BufferedImage;\nimport java.io.IOException;\nimport java.util.Random;\n\nimport javax.imageio.ImageIO;\nimport javax.servlet.ServletException;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\nimport com.sun.xml.internal.bind.util.Which;\n\n\/**\n * Servlet implementation class yanzhengmaa\n *\/\npublic class yanzhengmaa extends HttpServlet {\n\tprotected void doGet(HttpServletRequest request, HttpServletResponse response)\n\t\t\tthrows ServletException, IOException {\n\t\t\/\/ \u5f97\u5230\u753b\u677f\n\t\tint width = 200;\/\/ \u8bbe\u7f6e\u753b\u677f\u5bbd\n\t\tint height = 50;\/\/ \u8bbe\u7f6e\u753b\u677f\u9ad8\n\t\tBufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);\/\/ \u521b\u5efa\u753b\u677f\u5bf9\u8c61,\u7ed9\u5b9a\u53c2\u6570\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/ \u957f,\u5bbd,\u56fe\u7247\u6570\u636e\u7684\u6765\u6e90(INR_RGB)\n\n\t\t\/\/ \u5f97\u5230\u753b\u7b14\n\t\tGraphics g = bi.getGraphics();\n\t\t\n\t\t\/\/\u5f00\u59cb\u541f\u8bd7\u4f5c\u753b~\n\t\t\/\/\u753b\u80cc\u666f\n\t\tg.setColor(Color.RED);\/\/\u8bbe\u7f6e\u7b14\u989c\u8272\u4e3a\u7ea2\u8272,\u753b\u80cc\u666f\u989c\u8272\n\t\tg.fillRect(0, 0, width, height);\/\/\u7528\u7b14\u586b\u5145\u77e9\u5f62(\u989c\u8272)\n\t\t\n\t\t\/\/\u753b\u8fb9\u6846\n\t\tg.setColor(Color.black);\/\/\u8bbe\u7f6e\u7b14\u7684\u989c\u8272\u4e3a\u9ed1\u8272\n\t\tg.drawRect(0, 1, width - 1, height - 1 );\/\/\u53c2\u6570(\u5f00\u59cbx,\u5f00\u59cby,\u7ed3\u675fx,\u7ed3\u675fy)\u4ece\u5de6\u4e0a\u89d2\u5f00\u59cb\u753b\u77e9\u5f62\u5230\u53f3\u4e0b\u89d2. (-1\u662f\u8865\u9f50,\u56e0\u4e3a\u548c\u6570\u7ec4\u4e00\u6837\u4ece0\u5f00\u59cb\u81f3x-1\u5b9e\u4f53\u7ed3\u675f)\n\t\tg.drawRect(9, 9, width -20, height - 20 );\/\/\u81ea\u53d1\u6dfb\u52a0\u4e8c\u5c42\u6a2a\u6846\n\t\t\n\t\t\/\/\u753b\u5e72\u6270\u7ebf\n\t\tRandom r = new Random();\/\/\u521b\u5efa\u968f\u673a\u6570\u5bf9\u8c61\n\t\tint count = r.nextInt(10);\n\t\tfor (int i = 0; i &lt; count; i++) {\n\t\t\tg.setColor(Color.BLACK);\/\/\u8bbe\u7f6e\u7b14\u7684\u989c\u82721\n\t\t\tg.drawLine(r.nextInt(width-2)+1,r.nextInt(height-2)+1,r.nextInt(width-2)+1, r.nextInt(height-2)+1);\/\/\u7b14,\u753b\u76f4\u7ebf,(x,y,x,y)\n\t\t\tg.setColor(Color.BLUE);\/\/\u8bbe\u7f6e\u7b14\u7684\u989c\u82722\n\t\t\tg.drawLine(r.nextInt(width-2)+1,r.nextInt(height-2)+1,r.nextInt(width-2)+1, r.nextInt(height-2)+1);\n\t\t}\n\t\t\n\t\t\/\/\u5f00\u59cb\u7ed9\u9a8c\u8bc1\u7801\u52a0\u5b57\n\t\t\n\t\tString&#091;] akc = {&quot;\u6851&quot;,&quot;\u6d77&quot;,&quot;\u55e8&quot;,&quot;\u56db&quot;,&quot;\u884c&quot;,&quot;\u4e14&quot;,&quot;\u745e&quot;,&quot;\u9650&quot;,&quot;\u671f&quot;,&quot;\u9a91&quot;,&quot;\u5565&quot;,&quot;\u8d56&quot;,&quot;\u50bb&quot;,&quot;\u5947&quot;,&quot;\u54e5&quot;,&quot;\u9a8c&quot;,&quot;\u6574&quot;,&quot;1&quot;,&quot;\u7ea7&quot;,&quot;\u7a7a&quot;,&quot;\u7b49&quot;,&quot;\u7a77&quot;,&quot;\u6015&quot;,&quot;\u4e86&quot;,&quot;\u54e6&quot;,&quot;\u554a&quot;,&quot;\u4ece&quot;,&quot;\u662f&quot;,&quot;\u53bb&quot;};\/\/\u8bbe\u7f6e\u9a8c\u8bc1\u7801\u5b57\u5e93\n\t\t\n\t\tg.setColor(Color.CYAN);\/\/\u8bbe\u7f6e\u7b14\u7684\u989c\u8272\n\t\tg.setFont(new Font(&quot;\u5fae\u8f6f\u96c5\u9ed1&quot;, Font.BOLD, r.nextInt(8)+21));\/\/\u8bbe\u7f6e\u5b57\u4f53(\u5b57\u4f53,\u52a0\u7c97,\u5b57\u53f7)\n\t\tint x = 30;\/\/\u7b2c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u6587\u5b57\u5f00\u59cb\u4f4d\u7f6e\n\t\tStringBuilder str = new StringBuilder();\n\t\t\n\t\tfor (int i = 0; i &lt; 4; i++) { \/\/\u5faa\u73af\u56db\u6b21\n\t\t\tString yzm = akc&#091;r.nextInt(akc.length-1)];\/\/\u6bcf\u6b21\u4eceakc\u6570\u7ec4\u91cc\u968f\u673a\u51fa\u4e00\u4e2a\u5143\u7d20\u503c\u8d4b\u503c\u7ed9yzm\n\t\t\tstr.append(yzm); \/\/\u5c06yzm\u52a0\u5165\u5230\u5b57\u7b26\u7f13\u51b2\u533a\n\t\t\tg.drawString(String.valueOf(yzm), x, r.nextInt(34)+13);\/\/\u753b\u51fayzm\n\t\t\tx+=r.nextInt(41)+10;\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\/\/ \u663e\u793a\u51fa\u6765\uff0c\u4f7f\u7528\u6d41\u8f93\u51fa\n\t\tImageIO.write(bi, &quot;jpg&quot;, response.getOutputStream());\n\t}\n\n\tprotected void doPost(HttpServletRequest request, HttpServletResponse response)\n\t\t\tthrows ServletException, IOException {\n\t\t\/\/ TODO Auto-generated method stub\n\t\tdoGet(request, response);\n\t}\n\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u8fbe\u5230\u6548\u679c:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"200\" height=\"50\" data-id=\"148\" src=\"https:\/\/cn1.club\/wp-content\/uploads\/2025\/03\/1741750556-62bf1494576224.jpg\" alt=\"\" class=\"wp-image-148\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"200\" height=\"50\" data-id=\"149\" src=\"https:\/\/cn1.club\/wp-content\/uploads\/2025\/03\/1741750557-134c1494576224.jpg\" alt=\"\" class=\"wp-image-149\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"200\" height=\"50\" data-id=\"147\" src=\"https:\/\/cn1.club\/wp-content\/uploads\/2025\/03\/1741750556-490a1494576224.jpg\" alt=\"\" class=\"wp-image-147\"\/><\/figure>\n<\/figure>\n\n\n\n<p>\u8be5\u5199\u7684\u90fd\u5199\u4e86,\u6ce8\u91ca\u4e5f\u5f88\u8be6\u7ec6,\u5b8c\u5168\u81ea\u5df1\u6572\u7684.\u559c\u6b22\u7684\u53ef\u4ee5\u62ff\u53bb\u7814\u7a76\u54af!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fbe\u5230\u6548\u679c: \u8be5\u5199\u7684\u90fd\u5199\u4e86,\u6ce8\u91ca\u4e5f\u5f88\u8be6\u7ec6,\u5b8c\u5168\u81ea\u5df1\u6572\u7684.\u559c\u6b22\u7684\u53ef\u4ee5\u62ff\u53bb\u7814\u7a76\u54af!<\/p>\n","protected":false},"author":1,"featured_media":196,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"class_list":["post-146","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coder"],"_links":{"self":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":0,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/media\/196"}],"wp:attachment":[{"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}