Java -Generierungsprüfcode -Tool für Ihre Referenz. Der spezifische Inhalt ist wie folgt
Paket com.demo.utils; import Java.awt.BasicStroke; Import Java.awt.Color; Import Java.awt.font; Import Java.awt.graphics2d; Import Java.awt.RenderingHints; Java.io.FileOutputStream; Import Java.io.ioException; import Java.io.outputStream; Import Java.util.random; Import Javax.imageo.imageio;/** * Generate Verification Code * @author dongyangyang * @date 2017/3/13 12:31:31. statische zufällige random = new random (); // Random font style private final static int[] fontStyle = { Font.HANGING_BASELINE, Font.ITALIC, Font.LAYOUT_LEFT_TO_RIGHT, Font.LAYOUT_NO_LIMIT_CONTEXT, Font.LAYOUT_NO_START_CONTEXT, Font.LAYOUT_RIGHT_TO_LEFT, Font.CENTER_BASELINE, Font.PLAIN, Font.roman_baseline, font.trueType_font, font.type1_font, font.bold}; private endgültige statische String [] font = {"Ravie", "Forte", "Arial", "Courier"}; private endgültige statische int [] Xarr = {23, 24, 19, 20, 21}; private endgültige statische int [] yarr = {20, 21, 22, 23, 24, 25, 16, 17, 18}; private endgültige statische int [] font_size = {28, 29, 30, 21, 22, 23, 24, 27, 26, 25}; / ** * Zufallscode -Diagramm zeichnen * @param out * @param width Bufferedimage bi = new bufferedImage (Breite, Höhe, 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, Breite, Höhe); G.Drawrect (1, 1, Breite - 2, Höhe - 2); für (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)); für (int i = 0, len = value.length (); i <len; i ++) {string rand = string.valueof (value.charat (i)); int Grad = random.Nextint (23); if (i % 2 == 0) {Grad = Grad * (-1); } int x = xarr [(int) (math.random () * 5)] * i, y = yarr [(int) (math.random () * 8)]; G.Rotate (Math.Toradians (Abschluss), x, y); G.SetColor (Randcolor (48, 254)); g.drawstring (Rand, x + 8, y + 10); g.Rotate (-math.toradians (Grad), x, y); } // die mittlere Zeile des Bildes G.SetColor (Randcolor (0, 200)); // Die Breite ist die Linienbreite, Float Type BasicStroke BS = New Basicictroke (2); G.SetStroke (BS); // Zeichnen Sie die Kurve quadcurve2d.double curve = new quadcurve2d.double (0d, random.nextint (Höhe - 8) + 4, Breite / 2, Höhe / 2, Breite, random.Nextint (Höhe - 8) + 4); G.Draw (Kurve); // Zerstöre das Bild g.dispose (); Imageio.write (bi, "png", out); } private statische Schriftart getFont () {neue Schriftart (font [(int) (math.random () * 4)], fontStyle [(int) (math.random () * 12)], font_size [(int) (math.random () * 10)]; } private statische Farbe Randcolor (int fc, int bc) {// Erhalten Sie eine zufällige Farbe bei einem Bereich if (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); Neue Farbe zurückgeben (r, g, b); · 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '3', '5', '6', '7', '8', '9' }; public static String getRandom (int size) {stringBuilder sb = new StringBuilder (); für (int i = 0; i <size; i ++) {sb.append (c [math.abs (random.Nextint ()) % C.Length]); } return sb.toString (); } public static void main (String [] args) löst ioException {for (int i = 1; i <10; i ++) {FileOutputStream out = new FileOutputStream ("d: // bb"+i+". png"); zeichnen (raus, getrandom (4)); }}}Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.