Android图片添加竖排文字水印

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android图片添加竖排文字水印相关的知识,希望对你有一定的参考价值。

参考技术A 在相机设置里选择水印。
进入相机拍照界面,选择“水印模式”(或进入图库,打开某张图片,点击编辑-水印),然后选择一种带文字水印,点击虚线文本框,即可修改内容。

给图片添加文字水印

public void ImageWaterMarkText(string filename, ImageFormat format)
        {
            Image originalImage = Image.FromFile(filename);
            Graphics g = Graphics.FromImage(originalImage);
            
            Font drawFont = new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel);
           //找到图片旋转中点
float xpos = originalImage.Width > originalImage.Height ? originalImage.Width - originalImage.Height/ 2 : originalImage.Width / 2; float ypos = originalImage.Width > originalImage.Height ? originalImage.Height / 2 : originalImage.Height - originalImage.Width / 2; var triggleLeg = (originalImage.Width > originalImage.Height ? originalImage.Height : originalImage.Width) / 3; ar gPath = new GraphicsPath(); gPath.AddLine(originalImage.Width - triggleLeg, originalImage.Height, originalImage.Width, originalImage.Height - triggleLeg); gPath.AddLine(originalImage.Width, originalImage.Height - triggleLeg, originalImage.Width, originalImage.Height); gPath.AddLine(originalImage.Width, originalImage.Height, originalImage.Width - triggleLeg, originalImage.Height); g.FillPath(new SolidBrush(Color.FromArgb(120, Color.Black)), gPath);              g.TranslateTransform(xpos, ypos); g.RotateTransform(-45); SizeF crSize; string watermarkText;
watermarkText
= "测试文字"; crSize = g.MeasureString("Chine LianTong", drawFont); g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Red), -crSize.Width / 2, 250); watermarkText = DateTime.Now.ToString("Current: yyyy-MM-dd HH:mm"); g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Red), -crSize.Width / 2, 250 + crSize.Height + 5); g.Dispose(); MemoryStream stream = new MemoryStream(); originalImage.Save(stream, format); originalImage.Dispose(); Image img = Image.FromStream(stream); img.Save(filename); img.Dispose(); }

以上是关于Android图片添加竖排文字水印的主要内容,如果未能解决你的问题,请参考以下文章

Android给图片添加文字和水印

海报工厂之android 如何给图片添加水印和文字

WPS文字/word文档如何添加水印?

Android-Camera添加水印(最简单)

android EditText输入文字 数字时 里面的图片文字怎么消失 用的是哪个属性?

Android 生成分享长图并且添加全图水印