2010-10-21 108 views
2

我想從我從數據庫中獲取的文本生成圖像。我知道如何做到這一點,沒有任何問題,但是我需要幫助的是如何基於文本的數量動態縮小或增大圖像的邊界。我不知道在數據庫列中會有多少文本。有沒有辦法在生成的圖像中包裝文本?將動態文本轉換爲圖像

謝謝!

+0

什麼Image類? – 2010-10-21 15:49:23

+0

from system.drawing and system.drawing.imaging – adminJaxon 2010-10-21 15:57:11

回答

3

如果你知道你想要矩形有多大,你可以像下面這樣。

 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

真棒!這正是我所期待的! – adminJaxon 2010-10-21 16:32:06