2012-05-05 44 views
0


在图像上书写3维文字

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



这里是我的方法写在图像

private readonly string _textOnImage = ConfigurationManager.AppSettings["textOnImage"]; private readonly int _opacity = Int32.Parse(ConfigurationManager.AppSettings["opicity"]); private readonly int _red = Int32.Parse(ConfigurationManager.AppSettings["red"]); private readonly int _green = Int32.Parse(ConfigurationManager.AppSettings["green"]); private readonly int _blue = Int32.Parse(ConfigurationManager.AppSettings["blue"]); private int _fontSize = Int32.Parse(ConfigurationManager.AppSettings["fontSize"]); private readonly String _fontName = ConfigurationManager.AppSettings["fontName"];

private bool _havException { get; set; } private string _exceptionMessage { get; set; } private Bitmap SourceImage { get; set; } private Bitmap DestinationImage { get; set; } public ImageMethods() { _havException = false; _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; } }
+0

我已经把我的代码写在图像上的简单文本。我怎么能把文本转换成3D –

+0

用“手动绘制”,我的意思是你实际上应该**绘制代表文本的数字。 'DrawString'方法不能做3D文字。 – MarioDS

回答

0

是的,这是可能的文本,但你必须手工绘制。

请参阅this开始绘制图像。

接下来,探索System.Drawing命名空间,特别是Graphics类,它具有绘制方法并用于上述文章中。

+0

我编辑了我的问题,好心地建议我怎么做? –

+0

@krshekhar我认为你不明白,我不认为有实际写3D文本的方法。一种做法是使用双重轮廓文本。 – MarioDS

+0

你能否为我提供一些例子。 –