Ferramenta de código de verificação de geração Java para sua referência. O conteúdo específico é o seguinte
pacote com.demo.utils; importar java.awt.basicstroke; importar java.awt.color; importar java.awt.font; importar java.awt.graphics2d; importba.awt.rendinghints java.awt.geom.mquadbcurve2d; java.io.fileOutputStream; importar java.io.ioException; importar java.io.outputStream; importar java.util.random; importar javax.imageio.imageio;/** * gene Código de verificação * @author Dongyangyang * @date 2017/3/3/3/3/3/1321111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111odelurárias, obter uma divulgação. estático aleatório aleatório = novo aleatório (); // estilo de fonte aleatória private final static int [] fontStyle = {font.hanging_baseline, font.italic, font.layout_left_to_right, font.layout_no_limit_context, font.layout_no_start_contect, font.layout_rightx, Font.Roman_Baseline, Font.truetype_font, font.type1_font, font.bold}; String estática final privada [] font = {"ravie", "forte", "arial", "courier"}; private final static int [] xarr = {23, 24, 19, 20, 21}; private final estático int [] yarr = {20, 21, 22, 23, 24, 25, 16, 17, 18}; private final static int [] font_size = {28, 29, 30, 21, 22, 23, 24, 27, 26, 25}; / ** * Desenhe o diagrama de código aleatório * @param out * @param width * @param altura * @throws ioexception */ public static void draw (outputStream Out, String Value) lança ioexception {int width = 100, altura = 40; BufferImage bi = new bufferImage (largura, altura, bufferImage.type_int_rgb); Graphics2d g = (Graphics2d) bi.getGraphics (); g.setRanderingHint (renderinghints.key_antialiasing, renderinghints.value_antialias_on); g.setColor (Randcolor (240, 255)); G.FillRect (0, 0, largura, altura); G.Drawrect (1, 1, largura - 2, altura - 2); for (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 graus = aleatom.nextint (23); if (i % 2 == 0) {grau = grau * (-1); } int x = xarr [(int) (math.random () * 5)] * i, y = yarr [(int) (math.random () * 8)]; G.Rotate (Math.Toradians (grau), X, Y); g.setColor (Randcolor (48, 254)); G.DrawString (Rand, X + 8, Y + 10); g.rotate (-math.toradians (grau), x, y); } // A linha do meio da figura G.setColor (Randcolor (0, 200)); // A largura é a largura da linha, tipo de float BasicStroke bs = novo BasicStroke (2); G.SetStroke (BS); // desenhe a curva quadcurve2d.double curva = novo quadcurve2d.double (0d, random.nextInt (altura - 8) + 4, largura / 2, altura / 2, largura, aleatoriamente.nextint (altura - 8) + 4); G.Draw (curva); // Destrua a imagem G.Dispose (); Imageio.write (bi, "png", out); } Fonte estática privada getFont () {Retorne nova font (font [(int) (math.random () * 4)], fontstyle [(int) (math.random () * 12)], font_size [(int) (math.random () * 10)]); } cor estática privada Randcolor (int fc, int bc) {// Receba uma cor aleatória, dada a um intervalo se (fc> 255) {fc = 255; } if (bc> 255) {bc = 255; } int r = fc + aleatoriamente.NextInt (BC - FC); int g = fc + aleatoriamente.nextInt (bc - fc); int b = fc + aleatoriamente.nextInt (bc - fc); retornar nova cor (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', 'z', 'A', '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 (); for (int i = 0; i <tamanho; i ++) {sb.append (c [math.abs (random.nextInt ()) % c.lengthing]); } return sb.toString (); } public static void main (string [] args) lança ioexception {for (int i = 1; i <10; i ++) {FileOutputStream out = new FileOutputStream ("d: // bb"+i+". png"); desenhe (fora, getrandom (4)); }}}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.