views:

25

answers:

1

i want to add text to a image,because the text is too length,so i need check the text.width > image.width,if yes,i need automatic newline.also i need check the text.height > image.height,if yes i need other image to draw text.i also drawed text on image.

  public int makePictrue(string address, string pictrueAddress, string[] str, int[][] intPoint, Font font, SolidBrush solidB)
    {
        try
        {
            for (int i = 0; i < str.Length; i++)
            {
                Bitmap bmp;
                if (pictrueAddress.Trim() == "")
                {
                    bmp = new Bitmap("1.jpg");
                }
                else
                {
                    bmp = new Bitmap(pictrueAddress);
                }

                g = Graphics.FromImage((Image)bmp);

                g.DrawString(str[i], font, solidB, intPoint[i][0], intPoint[i][1]);

                MemoryStream stream = new MemoryStream();

                bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                bitmap = bmp;

            }

            return 1;
        }
        catch (Exception ex)
        {
            return 0;
        }
    }
+2  A: 

Use MeasureString to get the size of the text you want to draw and you need to specify which font you want to draw with and instead of giving the origin point to draw give the rectangle to draw within.

g.MeasureString()

You can use the StringFormat to set some text drawing options like NoClip, NoWrap...

A_Nablsi
thank you answer,i hava use MeasureString(),the key issue is i donot know how to automatic newline,How to judge that which the character reach the boundary.From which character to start another line.
pengwang