是否可以在圖像上書寫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; } }
我已經把我的代碼寫在圖像上的簡單文本。我怎麼能把文本轉換成3D –
用「手動繪製」,我的意思是你實際上應該**繪製代表文本的數字。 'DrawString'方法不能做3D文字。 – MarioDS