参照用のJava生成検証コードツール。特定のコンテンツは次のとおりです
パッケージcom.demo.utils; import java.awt.basicstroke; import java.awt.color; import java.awt.font; import java.awt.graphics2d; import java.awt.renderings; java.io.fileoutputStream; Import java.io.ioexception; Import java.io.outputStream; Import java.util.random; Import javax.imageio.imageio;/** * @author dongyangyang * @date 2017/3/13 12:31 * @vers class静的ランダム= new Random(); //ランダムフォントスタイルプライベート最終的な静的int [] fontstyle = {font.hanging_baseline、font.italic、font.layout_left_to_right、font.layout_no_start_context、font.layout_no_start_context font.plain、font.roman_baseline、font.truetype_font、font.type1_font、font.bold}; private final static string [] font = {"ravie"、 "forte"、 "arial"、 "courier"}; private final static int [] xarr = {23、24、19、20、21};プライベート最終静的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}; / ** *ランダムコード図を描画 * @param out * @param width * @param height * @throws ioexception */ public static void draw(outputstream out、string value)throws 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.SetColor(RandColor(240、255)); G.FillRect(0、0、幅、高さ); G.drawrect(1、1、width -2、height -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){degree = degree *(-1); } int x = xarr [(int)(math.random() * 5)] * i、y = yarr [(int)(math.random() * 8)]; G.Rotate(Math.Toradians(degree)、x、y); G.SetColor(RandColor(48、254)); G.ドローストリング(RAND、X + 8、Y + 10); g.rotate(-math.toradians(degree)、x、y); } //画像の中央線g.setcolor(randcolor(0、200)); //幅は線幅です。フロートタイプのbasicstroke bs = new basicstroke(2); G.SetStroke(BS); // quadcurve2d.double curve = new quadcurve2d.double(0d、random.nextint(height -8) + 4、width / 2、height / 2、width、random.nextint(height -8) + 4); G.Draw(Curve); //画像を破壊する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)]); } private static color randcolor(int fc、int bc){//範囲が与えられたランダムな色を取得する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);新しい色(r、g、b)を返します。 } private static char [] c = {'a'、 'b'、 'c'、 'd'、 'e'、 'f'、g '、' h '、' j '' '' '' '' '' '' '、' p '、' Q、 'r'、 's'、 'u 'c'、 'd'、 'e'、 'f'、 'g'、h '、' j '' '' '' '' '' '' '' '、q'、q '、' s '、' t '、' u '、' v '、' x '、' y '' '' '' '' '' '' '、 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)throws ioexception {for(int i = 1; i <10; i ++){fileoutputStream out = new fileoutputStream( "d:// bb"+i+"。png");描画(out、getrandom(4)); }}}上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。