linux C#下怎么实现往图片里添加文字

linux C#下怎么实现往图片里添加文字,第1张

最简单的方式就是通过GDI+在图片上画文字: Image image// 具体这张图是从文件读取还是从picturebox什么的获取你来指定using( Graphics g = Graphics.FromImage( image ) ){ g.DrawString( "xxxxx", new Font( "宋体", 13 ), Brushes.Red, new ...

//下面这两个文件位置根据你的需求,修改成你机子上的绝对位置。

//程序运行完后,会在newFile位置生成一个新文件。

string

oldFile

=

Environment.CurrentDirectory

+

"\\test.jpg"

string

newFile

=

Environment.CurrentDirectory

+

"\\test1.jpg"

Image

image

=

Image.FromFile(oldFile)

Graphics

graphic

=

Graphics.FromImage(image)

graphic.DrawString("绘画时间:2010年11月24日11:31:10",

new

Font("幼圆",

24f,

FontStyle.Regular),

new

SolidBrush(Color.Black),

100f,

100f)

image.Save(newFile)

image.Dispose()

graphic.Dispose()

/// <summary>

/// 在图片上增加文字水印

/// </summary>

/// <param name="Path">原服务器图片路径</param>

/// <param name="Path_sy">生成的带文字水印的图片路径</param>

protected void AddShuiYinWord(string Path, string Path_sy)

{

string addText = "测试水印"

System.Drawing.Image image = System.Drawing.Image.FromFile(Path)

System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image)

System.Drawing.Font f = new System.Drawing.Font("Verdana", 16)

System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Blue)

g.DrawString(addText, f, b, 15, 15)

g.Dispose()

image.Save(Path_sy)

image.Dispose()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11911860.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存