Herramienta de código de verificación de generación Java para su referencia. El contenido específico es el siguiente
paquete com.demo.utils; import java.awt.basicStroke; import java.awt.color; import java.awt.font; import java.awt.graphics2d; import java.awt.renderinghints; import java.awt.geom.quadcurve2d; import java.awt.image.image; import; java.io.fileOutputStream; import java.io.ioException; import java.io.outputStream; import java.util.random; import javax.imageio.imageio;/** * Generar el código de verificación * @author dongyangyang * @Date 2017/3/13 12:31 * @version 1.0 */@author dongyangyang * @Date 2017/3/3/13 12:31 * @version 1.0 */Clasión pública Autor static random 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}; cadena estática final privada [] font = {"Ravie", "forte", "Arial", "Courier"}; Private Final Static int [] xarr = {23, 24, 19, 20, 21}; Private Final Static int [] Yarr = {20, 21, 22, 23, 24, 25, 16, 17, 18}; Private final estática int [] font_size = {28, 29, 30, 21, 22, 23, 24, 27, 26, 25}; / ** * Dibuje el diagrama de código aleatorio * @param out * @param ancho * @param altura * @throws ioexception */ public static void Draw (outputStream Out, Value de cadena) arroja ioexception {int width = 100, altura = 40; BufferedImage bi = new BufferedImage (ancho, altura, 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, ancho, altura); G.Drawrect (1, 1, ancho - 2, altura - 2); para (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)); for (int i = 0, len = value.length (); i <len; i ++) {string rand = string.ValueOf (value.charat (i)); int grado = Random.NextInt (23); if (i % 2 == 0) {grado = grado * (-1); } int x = xarr [(int) (math.random () * 5)] * i, y = yarr [(int) (math.random () * 8)]; g.rotate (matemáticas. Toradianos (grado), x, y); G.SetColor (Randcolor (48, 254)); G.DrawString (rand, x + 8, y + 10); g.rotate (-math.toradians (grado), x, y); } // La línea media de la imagen G.SetColor (RandColor (0, 200)); // El ancho es el ancho de línea, tipo de flotación básica BS = nuevo básico (2); G.Setstroke (BS); // Dibuja la curva QuadCurve2D.Double Curve = New QuadCurve2D.Double (0D, Random.NextInt (altura - 8) + 4, ancho / 2, altura / 2, ancho, random.nextInt (altura - 8) + 4); G.Draw (curva); // destruir la imagen g.dispose (); Imageio.write (bi, "png", out); } private static font getFont () {return new Font (font [(int) (math.random () * 4)], fontstyle [(int) (math.random () * 12)], font_size [(int) (math.random () * 10)]); } color estático privado randcolor (int fc, int bc) {// obtener un color aleatorio dado un rango 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); devolver nuevo color (R, G, B); } private static char [] c = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', '»,', ',', ',', ',', ',', '. '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' 7 ',', ',', ',', ',', ',', ',', ',', ',', ',', ',', ',', public static String getRandom (int size) {StringBuilder sb = new StringBuilder (); para (int i = 0; i <size; i ++) {sb.append (c [math.abs (random.nextInt ()) % C.Length]); } return sb.ToString (); } public static void main (string [] args) lanza ioexception {for (int i = 1; i <10; i ++) {fileOutputStream out = new FileOutputStream ("d: // bb"+i+". png"); dibujar (fuera, getrandom (4)); }}}Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.