package com.cusc.nirvana.user.rnr.fp.util;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author stayAnd
 * @date 2022/6/22
 */
public class ImgUtil {

	/**
	 * 	水印文字颜色
 	 */
	private static Color color = new Color(255, 255, 255);


	/**
	 *
	 * @param imgStream 图片流
	 * @param logoText 文字水印内容
	 * @param suffix 图片后缀名
	 * @return
	 * @throws IOException
	 */
	public static InputStream addWorkMarkUpperLeftToInputStreamFile(InputStream imgStream, List<String> logoText, String suffix) throws IOException {

		BufferedImage img = ImageIO.read(imgStream);
		// 创建画笔
		Graphics2D pen = img.createGraphics();
		// 设置画笔颜色为白色
		pen.setColor(Color.WHITE);
		//pen.setColor(new Color(179, 250, 233, 200));
		// 设置画笔字体样式为微软雅黑，斜体，文字大小为20px
		pen.setFont(new Font("微软雅黑", Font.ITALIC, 20));
		// 写上水印文字和坐标
		pen.drawString("我是图片水印", 30, 550);

		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageIO.write(img, "png", os);
		InputStream input = new ByteArrayInputStream(os.toByteArray());
		return input;

	}


	private static int getCharLen(char c, Graphics2D g) {
		return g.getFontMetrics(g.getFont()).charWidth(c);
	}
}
