rain
2024-08-16 3430a3dd889ba51d06cbdb77014aa63d0a070e48
src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
@@ -1,5 +1,7 @@
package com.dji.sample.territory.utils;
import com.dji.sample.media.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.imageio.ImageIO;
@@ -12,7 +14,8 @@
import java.util.Date;
@Component
public class WaterMarkUtil {
    @Autowired
    private IFileService fileService;
    /**
     * 将图片加上水印并压缩
     *
@@ -23,7 +26,7 @@
     * @return 添加水印并压缩后的图片文件。
     * @throws IOException 如果读取或保存图片失败。
     */
    public static File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles) throws IOException, FontFormatException {
    public  File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles, int type) throws IOException, FontFormatException {
        double anglses = convertAngle(angles);
        String angel = angle(anglses);
        Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位)
@@ -36,12 +39,15 @@
        } catch (IOException e) {
            throw new IllegalArgumentException("读取图片失败" + e.getMessage());
        }
//        fileService.saveMarkFile(lotInfo.getWorkspaceId(),mediaFile,file1);
        // 创建 Graphics2D 对象以在图像上绘制水印
        Graphics2D g2d = originalImage.createGraphics();
        // 设置水印文字 "江西调查云"
        String watermarkText = "江西调查云";
        if (type == 1){
            watermarkText = "国土调查云";
        }
        float alpha = 0.8f; // 设置透明度为 0.7
        AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
        g2d.setComposite(alphaComposite);