package com.example.beijing_daxing.uitls;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

import java.security.MessageDigest;

public class CustomWatermarkTransformation extends BitmapTransformation {

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        // 获取原始图片的宽度和高度
        int width = toTransform.getWidth();
        int height = toTransform.getHeight();

        // 创建一个新的Bitmap，用于绘制带有水印的图片
        Bitmap watermarkedBitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);

        // 创建画布，并将原始图片绘制到画布上
        Canvas canvas = new Canvas(watermarkedBitmap);
        canvas.drawBitmap(toTransform, 0, 0, null);

        // 创建一个画笔，用于绘制水印
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(50);
        paint.setAntiAlias(true);

        // 设置水印的透明度
        paint.setAlpha(128);

        // 在指定位置绘制水印文字
        canvas.drawText("自定义水印1", width - 200, height - 50, paint);
        canvas.drawText("自定义水印2", width - 200, height - 80, paint);

        return watermarkedBitmap;
    }

    @Override
    public void updateDiskCacheKey(MessageDigest messageDigest) {}

}