【问题标题】:Writing 3 Dimension text on image在图像上书写 3 维文本
【发布时间】:2012-05-14 15:35:19
【问题描述】:


是否可以在图像上写 3D 文本。我正在使用带有 c# 的 asp.net。如果可能的话,请给我一些想法。



这是我在图像上写文字的方法

私有只读字符串 _textOnImage = ConfigurationManager.AppSettings["textOnImage"]; 私有只读 int _opacity = Int32.Parse(ConfigurationManager.AppSettings["opicity"]); 私有只读 int _red = Int32.Parse(ConfigurationManager.AppSettings["red"]); 私有只读 int _green = Int32.Parse(ConfigurationManager.AppSettings["green"]); 私有只读 int _blue = Int32.Parse(ConfigurationManager.AppSettings["blue"]); 私有 int _fontSize = Int32.Parse(ConfigurationManager.AppSettings["fontSize"]); 私有只读 String _fontName = ConfigurationManager.AppSettings["fontName"];

private bool _havException { get;放; } 私有字符串 _exceptionMessage { 获取;放; } 私有位图 SourceImage { 获取;放; } 私有位图 DestinationImage { 获取;放; } 公共图像方法() { _havException = 假; _exceptionMessage = string.Empty; }

public void AddWatermarkText(Image img, String TextOnImage) { TextOnImage = TextOnImage ?? _textOnImage; try { var lobFromImage = Graphics.FromImage(img); FindFontSize(lobFromImage, img, TextOnImage); var lobFont = new Font(_fontName, _fontSize, FontStyle.Regular); var lintTextHw = lobFromImage.MeasureString(TextOnImage, lobFont); var lintTextOnImageWidth = (int)lintTextHw.Width; var lintTextOnImageHeight = (int)lintTextHw.Height; var lobSolidBrush = new SolidBrush(Color.FromArgb(_opacity, Color.FromArgb(_red, _green, _blue))); var posLeft = (img.Width - lintTextOnImageWidth) / 2; posLeft = posLeft > 0 ? posLeft : 5; var lobPoint = new Point(posLeft, (img.Height / 2) - (lintTextOnImageHeight / 2)); // var lobPoint = new Point(RandomNumber(0, img.Width - lintTextOnImageWidth), RandomNumber(0, img.Height - lintTextOnImageHeight)); lobFromImage.DrawString(TextOnImage, lobFont, lobSolidBrush, lobPoint, StringFormat.GenericTypographic); lobFromImage.Dispose(); lobSolidBrush.Dispose(); lobFont.Dispose(); } catch (Exception ex) { _havException = true; _exceptionMessage = ex.Message; } return; } private void FindFontSize(Graphics lobGraphics, Image lobImage ,String textOnImage ) { var lobFont = new Font(_fontName, _fontSize, FontStyle.Regular); var lintTextHw = lobGraphics.MeasureString(textOnImage, lobFont); var lintTextOnImageWidth = (int)lintTextHw.Width; var lintImageWidth = lobImage.Width ; while (lintImageWidth < lintTextOnImageWidth) { lobFont = new Font(_fontName, _fontSize--, FontStyle.Regular); lintTextOnImageWidth = (int)lobGraphics.MeasureString(textOnImage, lobFont).Width; } }

【问题讨论】:

  • 我已经把我的代码放在图像上写简单的文本。如何将文本转换为 3D
  • 对于“手动绘制”,我的意思是您实际上应该在其上绘制代表文本的图形。 DrawString 方法不能做 3D 文本。

标签: asp.net c#-4.0


【解决方案1】:

是的,这是可能的,但您必须手动绘制。

请参考this 开始在图像上绘图。

接下来,探索System.Drawing 命名空间,特别是Graphics 类,它有draw 方法,也用于上述帖子。

【讨论】:

  • @krshekhar 我不认为你明白,我认为没有办法实际编写 3D 文本。一种方法是使用双轮廓文本。
  • 你能给我举个例子吗?
  • @krshekhar 对不起,我不能,没有传统的方式可以做你想做的事......
猜你喜欢
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 2015-11-21
  • 2013-08-06
  • 1970-01-01
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
相关资源
最近更新 更多