Dynamic Text into an Image
I would like to generate an image from text that I g开发者_Go百科et 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!
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
}
精彩评论