开发者

Dynamic Text into an Image

开发者 https://www.devze.com 2023-01-21 22:08 出处:网络
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

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


        }
0

精彩评论

暂无评论...
验证码 换一张
取 消