1 Graphics2D graphics = (Graphics2D) image.getGraphics(); 2 graphics.setColor(color); 3 RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 4 hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); 5 graphics.setRenderingHints(hints); 6 FontRenderContext frc = graphics.getFontRenderContext(); 7 8 char[] wordChars = text.toCharArray(); 9 int startPosY = 40; 10 int startPosX = 60; 11 Random random = new Random(); 12 for (int i = 0; i < wordChars.length; i++) { 13 graphics.setFont(fonts[0]); 14 char[] charToDraw = new char[] { wordChars[i] }; 15 GlyphVector fontGV = fonts[0].createGlyphVector(frc, charToDraw); 16 Shape textShape = fontGV.getOutline(); 17 AffineTransform rotate45 = AffineTransform.getRotateInstance(30 * Math.PI, 0, 0); 18 Shape rotatedText = rotate45.createTransformedShape(textShape); 19 graphics.translate(startPosX, startPosY); 20 graphics.draw(rotatedText); 21 startPosX = (random.nextInt(3) + 1) * 10; 22 startPosY = (random.nextInt(3) + 1); 23 } 24 25 graphics.dispose();
扣空心,只支持一个一个字符的~,多个字符需要循环draw.