自己写的,觉得非常简单经典。java给图片添加文子或者水印都需要用到。
try{ String fileName = "D:/certificate.jpg";// 源图路径 String outFileName = "D:/test.jpg";// 新生成图片路径 FileInputStream fis = new FileInputStream(fileName); BufferedImage outImg = ImageIO.read(fis); Graphics g = outImg.getGraphics(); g.setFont(new Font("Times New Roman",Font.ROMAN_BASELINE,18)); g.setColor(new Color(102,102,102)); //设字体为黑色,否则就是白色 g.drawString("houyongsssssss", 100, 215); g.dispose();//保存修改 FileOutputStream outPictrue = new FileOutputStream(outFileName); ImageIO.write(outImg, "JPEG", outPictrue); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }