addTextWatermark static method
给图片添加文字水印
Implementation
static Future<File> addTextWatermark(File file, String text,
{Color color = Colors.white,
double fontSize = 18,
Offset offset = const Offset(10, 10)}) async {
try {
// 读取图片数据
final bytes = await file.readAsBytes();
// 添加水印
final updatedBytes = await addTextWatermarkToBytes(bytes, text,
color: color, fontSize: fontSize, offset: offset);
// 创建新的临时文件
final tempDir = await getTemporaryDirectory();
final tempFile = File('${tempDir.path}/watermarked_image.jpg');
await tempFile.writeAsBytes(updatedBytes);
return tempFile;
} catch (e) {
debugPrint('Error adding watermark: $e');
rethrow;
}
}