| | |
| | | * @throws IOException 如果读取或保存图片失败。 |
| | | */ |
| | | public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng, Double angles) throws IOException { |
| | | String author="机巢"; |
| | | String author="中图智绘无人机"; |
| | | String angel=angle(angles); |
| | | Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位) |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | |
| | | // 创建 Graphics2D 对象以在图像上绘制水印 |
| | | Graphics2D g2d = originalImage.createGraphics(); |
| | | |
| | | // 设置水印文字 "国土调查云" |
| | | // 设置水印文字 "江西调查云" |
| | | String watermarkText = "江西调查云"; |
| | | float alpha = 0.5f; // 设置透明度为 0.5 |
| | | float alpha = 0.7f; // 设置透明度为 0.7 |
| | | AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); |
| | | g2d.setComposite(alphaComposite); |
| | | g2d.setFont(new Font("宋体", Font.BOLD, 100)); // 使用宋体字体 |
| | | g2d.setFont(new Font("宋体", Font.BOLD, 150)); // 使用宋体字体 |
| | | FontMetrics fms = g2d.getFontMetrics(); |
| | | int textHeights = fms.getHeight(); |
| | | |
| | | // 设置水印位置(左居中) |
| | | int x1 = 100; // 左边距离图片左边缘的距离 |
| | | int y1 = (originalImage.getHeight() - textHeights) / 2; // 垂直居中 |
| | | int x1 = 600; // 左边距离图片左边缘的距离 |
| | | int y1 = (originalImage.getHeight() - textHeights) -800; // 垂直居中 |
| | | // 旋转35度角 |
| | | double angle = Math.toRadians(35); |
| | | double angle = Math.toRadians(50); |
| | | AffineTransform at = AffineTransform.getRotateInstance(angle, x1, y1); |
| | | g2d.setTransform(at); |
| | | // 绘制左上角旋转水印文字 |
| | |
| | | g2d.setTransform(new AffineTransform()); |
| | | // 设置文本位置(右下角) |
| | | int x2 = originalImage.getWidth() - textWidth - 30; // 右对齐的 x 坐标 |
| | | int y2 = originalImage.getHeight() - textHeight - 65; // 最底部位置 y 坐标 |
| | | int y2 = originalImage.getHeight() - textHeight - 68; // 最底部位置 y 坐标 |
| | | // 绘制文本信息 |
| | | String[] lines = extraInfo.split("\n"); |
| | | for (String line : lines) { |