2012-05-05 13 views
0


イメージに3次元テキストを書く

イメージに3Dテキストを書くことは可能ですか?私はC#とasp.netを使用しています。可能であれば、私にアイ​​デアを教えてください。ここ



画像

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テキストを書く方法がないと思う。それを行うための1つのテクニックは、二重アウトラインテキストを使用することです。 – MarioDS

+0

あなたは私にそれのためのいくつかの例を教えてくれますか? –