tags:

views:

27

answers:

1

Hello, I would like to generate an image from text that I get from a database. I know how to do that no problem, however where I need help is how to dynamically shrink or grow the bounds of the image based on how much text there is. I will not know how much text there will be in the database column. Is there a way to wrap text in a generated image somehow?

Thanks!

+1  A: 

If you know how big you want the rectangle to be you can something like the following.

        Bitmap bmp = new Bitmap(1000,1000);

        using (Graphics g = Graphics.FromImage(bmp))
        {

          string s = "This string will be wrapped in the output rectangle";
          RectangleF rectf = new RectangleF (10, 100, 200, 200);

          g.DrawString(s, DefaultFont, Brushes.Red, rectf);

          this.BackgroundImage = bmp; //For testing purposes set the form's background to the image


        }
Conrad Frix
AWESOME! This is exactly what I was looking for!
adminJaxon