शेखर
शेखर

Reputation: 17614

Writing 3 Dimension text on image


Is it possible to write 3D text on image. I am using asp.net with c#. If possible then kindly give me some Idea.



here is my method to write text on image

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; } }

Upvotes: 1

Views: 442

Answers (2)

Gray Programmerz
Gray Programmerz

Reputation: 609

3d text

enter image description here

I found a great article regrading it here.

Although, the author is using e.Graphics mostly inside of OnPaint(...) event. But you can create your own graphics as well something like:

var image = Image.FromFile(path);
// or
var image = Image.FromStream(stream);
// or
var width = 100;
var height= 100;
var image = new Bitmap(width, height);

var graphics = Graphics.FromBitmap(image);

and do the rest like in article explained.

Upvotes: 0

MarioDS
MarioDS

Reputation: 13063

Yes this is possible, but you'll have to draw it manually.

Please refer to this to get started drawing on an image.

Next, explore the System.Drawing namespace, in particular the Graphics class that has draw methods and is used in the above-mentioned post too.

Upvotes: 2

Related Questions