how to convert multiline textbox text to image
-
hello sir ' my problem is that i am trying to convert multiline textbox text to gif format. every thing works fine except the text which is to be converted convert only first line . i think it is converting text box text as a single line any suggestion plz here is my code Bitmap b = new Bitmap(330,TextBox1.Text.Length, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(b); string message; g.Clear(Color.Yellow); message = TextBox1.Text; StringFormat format = new StringFormat(); int alignment = 1; if (alignment == 1) { format.Alignment = StringAlignment.Near; } format.LineAlignment = StringAlignment.Center; g.DrawString(TextBox1.Text, new Font("Kruti Dev 010", 12, FontStyle.Regular), new SolidBrush(Color.Black),new PointF(2.5F,.5F) ,format); Response.ContentType = "image/gif"; b.Save(Server.MapPath("IMG\\"+img+".gif"), ImageFormat.Gif); b.Dispose(); Response.Write("file uploaded Successfully"); }
-
hello sir ' my problem is that i am trying to convert multiline textbox text to gif format. every thing works fine except the text which is to be converted convert only first line . i think it is converting text box text as a single line any suggestion plz here is my code Bitmap b = new Bitmap(330,TextBox1.Text.Length, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(b); string message; g.Clear(Color.Yellow); message = TextBox1.Text; StringFormat format = new StringFormat(); int alignment = 1; if (alignment == 1) { format.Alignment = StringAlignment.Near; } format.LineAlignment = StringAlignment.Center; g.DrawString(TextBox1.Text, new Font("Kruti Dev 010", 12, FontStyle.Regular), new SolidBrush(Color.Black),new PointF(2.5F,.5F) ,format); Response.ContentType = "image/gif"; b.Save(Server.MapPath("IMG\\"+img+".gif"), ImageFormat.Gif); b.Dispose(); Response.Write("file uploaded Successfully"); }
monu_khan wrote:
TextBox1.Text.Length
This is more than a little insane. You need to use MeasureString to get a width and height.
monu_khan wrote:
Graphics g = Graphics.FromImage(b);
Why not use a using statement, instead of leaking resources ?
monu_khan wrote:
new Font("Kruti Dev 010", 12, FontStyle.Regular)
Another leak, plus if you change the font, it means you need to measure the string for that font. Although you're using ASP.NET, this question has nothing to do with ASP.NET, it's about some basic graphics work. Why do you waste server space by saving a string a a bitmap instead of as text ?
monu_khan wrote:
int alignment = 1; if (alignment == 1)
Bizarre.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.