src/main/java/me/codeboy/common/base/io/CBImage.java
public BufferedImage drawText(String text, int fontSize, Color color) {
        Graphics g = image.getGraphics();
        g.setColor(color);
        Font f = new Font("宋体", Font.BOLD, fontSize);
        g.setFont(f);
        int len = text.length();
        g.drawString(text, (width - fontSize * len) / 2,
                (height + (int) (fontSize / 1.5)) / 2);
        g.dispose();
        return image;
    }
public BufferedImage drawText(String text, int fontSize, Color color) {
        Graphics g = image.getGraphics();
        g.setColor(color);
        Font f = new Font("宋体", Font.BOLD, fontSize);
        g.setFont(f);
        int len = text.length();
        g.drawString(text, (width - fontSize * len) / 2,
                (height + (int) (fontSize / 1.5)) / 2);
        g.dispose();
        return image;
    }
public BufferedImage drawText ( String text , int fontSize , Color color ) { Graphics g = image . getGraphics ( ) ; g . setColor ( color ) ; Font f = new Font ( "宋体", Fo n .BOL D , fo n Size); g . setFont ( f ) ; int len = text . length ( ) ; g . drawString ( text , ( width - fontSize * len ) / 2 , ( height + ( int ) ( fontSize / 1.5 ) ) / 2 ) ; g . dispose ( ) ; return image ; }
在图片上写字

@param text     字符串
@param fontSize 字体大小
@param color    字体颜色
@return 图片
在图片上写字