참조를위한 Java Generation Verification Code 도구. 특정 내용은 다음과 같습니다
package 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 java.io.fileoutputStream; import java.io.ioexception; import java.io.outputstream; import java.util.random; import javax.imageio.imageio;/** * vertification code * @uthor dongyangyang * @date 2017/3/13 12:31 */version 1.0 */probliceation 1.0 */version 1.0 */version. 정적 랜덤 = 새로운 랜덤 (); // 랜덤 글꼴 스타일 개인 최종 정적 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_lleft, font.menter_baselle, font.menter_basely, font. font.roman_baseline, font.truetype_font, font.type1_font, font.bold}; 개인 최종 정적 문자열 [] font = { "ravie", "forte", "arial", "택배"}; 개인 최종 정적 int [] xarr = {23, 24, 19, 20, 21}; 개인 최종 정적 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 */ public static void draw (outputStream out, 문자열 값) IoException {int width = 100, height = 40; BufferedImage bi = New BufferedImage (너비, 높이, BufferedImage.type_int_rgb); Graphics2d g = (Graphics2d) bi.getGraphics (); G.SetRenderingHint (renderingHints.key_antialiasing, renderingHints.Value_antialias_on); G. 세트 콜러 (Randcolor (240, 255)); G.FillRect (0, 0, 너비, 높이); G.DrawRect (1, 1, 너비 -2, 높이 -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 degree = random.nextint (23); if (i % 2 == 0) {degress = dection * (-1); } int x = xarr [(int) (math.random () * 5)] * i, y = yar [(int) (math.random () * 8)]; G.Rotate (Math.Toradians (학위), X, Y); G. 세트 콜러 (Randcolor (48, 254)); G.DrawString (rand, x + 8, y + 10); g.rotate (-math.toradians (학위), x, y); } // 그림의 중간 줄 G.setColor (randcolor (0, 200)); // 너비는 선 너비, 플로트 유형 기본 스트로크 BS = 새로운 기본 스트로크 (2)입니다. G.SetStroke (BS); // 곡선 QuadCurve2d.double Curve = New QuadCurve2d.Double (0D, random.nextInt (높이 -8) + 4, 너비 / 2, 높이 / 2, 너비, Random.NextInt (높이 -8) + 4); G.Draw (곡선); // 이미지 파괴 g.dispose (); imageio.write (bi, "png", out); } private static font getfont () {return new Font (font [(int) (math.random () * 4)], fontstyle [(int) (int) (ath.random () * 12)], font_size [(int) (ath.random () * 10)]; } private static color 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); } 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', '', ',', ',' ', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '3', '', '', ',', ',', ',', ',' ' public static string getrandom (int size) {StringBuilder sb = new StringBuilder (); for (int i = 0; i <size; i ++) {sb.append (c [math.abs (random.nextint ()) % c.length]; } return sb.toString (); } public static void main (String [] args)은 ioexception {for (int i = 1; i <10; i ++) {fileoutputStream out = new FileOutputStream ( "d : // bb"+i+". png"); 그리기 (outrandom (4)); }}}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.