@GetMapping("/waterMark")
public String waterMark(Integer pageNumber, @CurrentUser Member currentUser, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws IOException {
Font font = new Font("微软雅黑", Font.PLAIN, 28); //水印字体
String waterMarkContent="we1hjk"; //水印内容
Color color=new Color(0,0,0,128); //水印图片色彩以及透明度
// 读取原图片信息
File srcImgFile = new File(request.getSession().getServletContext().getRealPath("/")+"newResources/share/images/timg.jpg");//得到文件
Image srcImg = ImageIO.read(srcImgFile);//文件转化为图片
int srcImgWidth = srcImg.getWidth(null);//获取图片的宽
int srcImgHeight = srcImg.getHeight(null);//获取图片的高
// 加水印
BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufImg.createGraphics();
g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null);
g.setColor(color); //根据图片的背景设置水印颜色
java水印,以输出流将水印后的图片返回给页面直接提示下载
最新推荐文章于 2024-05-23 21:48:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)