locked
Write text on an image. I want to word wrap it. Long line to be word wrapped. RRS feed

  • Question

  • User-1725039537 posted

    Hi,

     

    I am trying to write the string on an image. The string is getting written, but lenght more and the string gets half written, but wont word wrap and form the new line.

     

    Code:

     

    using (Graphics g = Graphics.FromImage((System.Drawing.Image)result))
            {
                g.DrawImage(src, 0, 0, newWidth, newHeight);
                Font f = new Font("Arial", 9, FontStyle.Bold);
                StringFormat f1 = new StringFormat(StringFormatFlags.NoClip);
                f1.Alignment = StringAlignment.Center;
                f1.LineAlignment = StringAlignment.Far;


                string name = (string)Session["strings"];
                PointF drawPoint = new PointF(70.0F, 80.0F);
                SolidBrush brush2 = new SolidBrush(Color.FromArgb(74, 75, 75));
                g.DrawString(name, f, brush2, drawPoint, f1);


            }

     

    Any Idea?

     

     

     

    Saturday, October 17, 2009 7:11 AM

Answers

  • User955742345 posted

    Instead of using a PointF to draw the string, use a Rectangle  StringFormatFlags includes an option called StringFormatFlags.NoWrap, which is causing the problem you mentioned.

    From the Object Browser summary of StringFormatFlags.NoWrap:

    Text wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 20, 2009 1:44 AM

All replies

  • User955742345 posted

    Instead of using a PointF to draw the string, use a Rectangle  StringFormatFlags includes an option called StringFormatFlags.NoWrap, which is causing the problem you mentioned.

    From the Object Browser summary of StringFormatFlags.NoWrap:

    Text wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 20, 2009 1:44 AM
  • User-1725039537 posted

    It worked.

     

    Thanks. 

    Tuesday, October 20, 2009 5:36 AM