| | |
| | | package com.dji.sample.territory.utils; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.*; |
| | | import java.awt.geom.AffineTransform; |
| | |
| | | import java.util.Date; |
| | | |
| | | import static com.dji.sample.territory.utils.ImgZipUtil.compressImageAndGetFile; |
| | | |
| | | @Component |
| | | public class WaterMarkUtil { |
| | | /** |
| | | * 将图片加上水印并压缩 |
| | | * |
| | | * @param file |
| | | * @param path |
| | | * @param pssj |
| | | * @param lat |
| | | * @param lng |
| | | * @return 添加水印并压缩后的图片文件。 |
| | | * @throws IOException 如果读取或保存图片失败。 |
| | | */ |
| | | public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng, Double angles) throws IOException, FontFormatException { |
| | | public static File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles) throws IOException, FontFormatException { |
| | | |
| | | String angel=angle(angles); |
| | | Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位) |
| | |
| | | g2d.setComposite(alphaComposite); |
| | | String extraInfo = String.format("Lon:%.9f Lat:%.6f\n%s 时间:%s", lng, lat,angel,sd); |
| | | |
| | | File fontFile = new File("src/main/java/com/dji/sample/territory/utils/MiSans-Normal.ttf"); // 替换为你的字体文件路径 |
| | | File fontFile = new File("/tmp/jave/MiSans-Normal.ttf"); // 替换为你的字体文件路径 |
| | | Font customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile).deriveFont(36.00F); |
| | | // 注册字体 |
| | | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |