เครื่องมือรหัสการตรวจสอบการสร้าง Java สำหรับการอ้างอิงของคุณ เนื้อหาเฉพาะมีดังนี้
แพ็คเกจ com.demo.utils; นำเข้า java.awt.basicstroke; นำเข้า java.awt.color; นำเข้า java.awt.font; นำเข้า java.awt.graphics2d; นำเข้า java.awt.renderinghints นำเข้า java.Awt.geom.Geom.geom. java.io.FileOutputStream; นำเข้า java.io.ioException; นำเข้า java.io.OutputStream; นำเข้า java.util.random; นำเข้า Javax.imageio.imageio;/** * สร้างรหัสการตรวจสอบ * @author Dongyangyang * @date 2017/3/13 แบบสุ่มแบบคงที่ = ใหม่สุ่ม (); // แบบสุ่มรูปแบบสไตล์ส่วนตัวสุดท้าย int [] fontstyle = {font.hanging_baseline, font.italic, font.layout_left_to_right, font.layout_no_limit_context, font.layout_no_start_context font.roman_baseline, font.truetype_font, font.type1_font, font.bold}; สตริงคงสุดท้ายส่วนตัว [] font = {"Ravie", "Forte", "Arial", "Courier"}; INT คงที่ครั้งสุดท้ายส่วนตัว [] XARR = {23, 24, 19, 20, 21}; INT คงที่ครั้งสุดท้ายส่วนตัว int [] yarr = {20, 21, 22, 23, 24, 25, 16, 17, 18}; INT คงที่ครั้งสุดท้ายส่วนตัว [] FONT_SIZE = {28, 29, 30, 21, 22, 23, 24, 27, 26, 25}; / ** * วาดไดอะแกรมโค้ดแบบสุ่ม * @param out * @param width * @param height * @throws ioexception */ โมฆะคงที่สาธารณะวาด (เอาท์พุทสตรีมออก, ค่าสตริง) พ่น ioexception {int width = 100, ความสูง = 40; bufferedImage bi = bufferedImage ใหม่ (ความกว้าง, ความสูง, bufferedImage.type_int_rgb); graphics2d g = (graphics2d) bi.getGraphics (); g.setrenderinghint (renderinghints.key_antialiasing, renderinghints.value_antialias_on); G.SetColor (RandColor (240, 255)); G.FillRect (0, 0, ความกว้าง, ความสูง); G.DrawRect (1, 1, ความกว้าง - 2, ความสูง - 2); สำหรับ (int i = 0; i <10; i ++) {g.setColor (randColor (150, 250)); G.Drawoval (Random.nextint (110), Random.nextint (24), 5 + random.nextint (10), 5 + random.nextint (10)); } G.SetFont (getFont ()); G.SetColor (RandColor (XARR [(int) (math.random () * 5)], 254)); สำหรับ (int i = 0, len = value.length (); i <len; i ++) {string rand = string.valueof (value.charat (i)); ระดับ int = random.nextint (23); if (i % 2 == 0) {องศา = องศา * (-1); } int x = xarr [(int) (math.random () * 5)] * i, y = yarr [(int) (math.random () * 8)]; G.rotate (Math.Toradians (ปริญญา), X, Y); G.SetColor (RandColor (48, 254)); G.DrawString (แรนด์, x + 8, y + 10); G.rotate (-Math.Toradians (องศา), x, y); } // เส้นตรงกลางของรูปภาพ G.SetColor (RandColor (0, 200)); // ความกว้างคือความกว้างของเส้น, ประเภทลอย basicstroke bs = basicstroke ใหม่ (2); G.SetStroke (BS); // วาดเส้นโค้ง quadcurve2d.double curve = ใหม่ quadcurve2d.double (0d, random.nextint (ความสูง - 8) + 4, ความกว้าง / 2, ความสูง / 2, ความกว้าง, สุ่ม. nextint (ความสูง - 8) + 4); G.Draw (เส้นโค้ง); // ทำลายภาพ g.dispose (); imageio.write (bi, "png", ออก); } ฟอนต์แบบคงที่ส่วนตัว getFont () {ส่งคืนแบบอักษรใหม่ (ตัวอักษร [(int) (math.random () * 4)], FontStyle [(int) (math.random () * 12)], font_size [int) (math.random () * 10)); } สีสแตติกส่วนตัว randcolor (int fc, int bc) {// รับสีแบบสุ่มให้ช่วงถ้า (fc> 255) {fc = 255; } if (bc> 255) {bc = 255; } int r = fc + random.nextint (bc - fc); int g = fc + random.nextint (bc - fc); int b = fc + random.nextint (bc - fc); คืนสีใหม่ (R, G, B); } char ส่วนตัวคงที่ [] c = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'm', 'n', '' '' '' '' '' ' 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', '' '' '' '' '' '' '' '' ' สตริงคงที่สาธารณะ getRandom (ขนาด int) {StringBuilder sb = new StringBuilder (); สำหรับ (int i = 0; i <size; i ++) {sb.append (c [math.abs (random.nextint ()) % c.length]); } return sb.toString (); } โมฆะคงที่สาธารณะหลัก (สตริง [] args) พ่น ioexception {สำหรับ (int i = 1; i <10; i ++) {fileOutputStream out = ใหม่ fileOutputStream ("d: // bb"+i+". png"); วาด (ออก, getrandom (4)); -ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น