From d2ec0c9b01dbfbc930c0d669d026589412335556 Mon Sep 17 00:00:00 2001 From: xiaji Date: Mon, 2 Mar 2026 22:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B0=B4=E5=8D=B0=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA=E5=BA=95=E9=83=A8=E4=B8=AD=E5=A4=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspection/camera/util/ImageProcessor.kt | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/inspection/camera/util/ImageProcessor.kt b/app/src/main/java/com/inspection/camera/util/ImageProcessor.kt index c5238d4..5ccd873 100644 --- a/app/src/main/java/com/inspection/camera/util/ImageProcessor.kt +++ b/app/src/main/java/com/inspection/camera/util/ImageProcessor.kt @@ -99,41 +99,51 @@ object ImageProcessor { locationText: String, style: WatermarkStyle ): Bitmap { + android.util.Log.d("ImageProcessor", "addWatermark called, timeText=$timeText, locationText=$locationText") + val result = sourceBitmap.copy(Bitmap.Config.ARGB_8888, true) val canvas = Canvas(result) + + // 使用固定的字体大小,基于图片宽度比例 + val baseFontSize = result.width / 40f // 字体大小为图片宽度的1/40 val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { - textSize = style.fontSize * result.density + textSize = baseFontSize color = style.textColor.toArgb() typeface = Typeface.DEFAULT_BOLD + textAlign = Paint.Align.CENTER } val watermarkText = "$timeText $locationText" val textWidth = paint.measureText(watermarkText) val textHeight = paint.fontMetrics.let { it.descent - it.ascent } + + android.util.Log.d("ImageProcessor", "Watermark: width=$textWidth, height=$textHeight, text=$watermarkText") - // 计算位置(左下角) - val padding = 20f * result.density - val x = padding + // 计算位置(底部中央) + val padding = result.width / 30f // 边距为图片宽度的1/30 + val x = result.width / 2f val y = result.height - padding // 绘制背景 - // 通过ARGB判断来决定是否绘制背景,避免混用 Android Color 与 Compose Color 的类型问题 val bgColorInt = style.backgroundColor.toArgb() + android.util.Log.d("ImageProcessor", "Background color int: $bgColorInt") if (bgColorInt != 0) { val bgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = bgColorInt } val bgRect = RectF( - x - 10, - y - textHeight - 10, - x + textWidth + 10, - y + 10 + x - textWidth / 2 - padding / 2, + y - textHeight - padding / 2, + x + textWidth / 2 + padding / 2, + y + padding / 2 ) canvas.drawRoundRect(bgRect, 8f, 8f, bgPaint) + android.util.Log.d("ImageProcessor", "Background drawn at x=$x, y=$y") } // 绘制文字 canvas.drawText(watermarkText, x, y, paint) + android.util.Log.d("ImageProcessor", "Text drawn at x=$x, y=$y") return result }