0


画像に 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"]); private int _fontSize = Int32.Parse(ConfigurationManager.AppSettings["fontSize"]); private readonly String _fontName = ConfigurationManager.AppSettings["fontName"];

プライベート bool _havException { get; 設定; } プライベート文字列 _exceptionMessage { get; 設定; } プライベート ビットマップ SourceImage { get; 設定; } プライベート ビットマップ DestinationImage { get; 設定; } 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; } }
4

1 に答える 1

0

はい、これは可能ですが、手動で描画する必要があります。

画像への描画を開始するには、これを参照してください。

次に、System.Drawing名前空間、特に描画メソッドがあり、上記の投稿でも使用されているGraphicsクラスを調べます。

于 2012-05-05T07:43:07.277 に答える