2011-03-03 65 views
1

我似乎無法讓我寫我的形象出現在這裏的文字是我在使用文字無法顯示在C#位圖圖像

//Creates a bitmap with the path to the current image 
Bitmap LabelImage = new Bitmap(dtImages.Rows[intCurrentImage]["ImageURL"].ToString()); 

Graphics graphic = Graphics.FromImage(LabelImage); 

graphic.DrawString("Hello", new Font("Tahoma",40), Brushes.Azure, new System.Drawing.Point(0,0)); 

//put Image that I just created and put the text on into an Infragistics UltraPicureBox 
picImage.Image = LabelImage 

回答

0

我只是嘗試這樣做

Bitmap bitmap = new Bitmap("C:\\Untitled.png"); 
Graphics g = Graphics.FromImage(bitmap); 
g.DrawString("Hello", new Font("Tahoma", 40), Brushes.Azure, new System.Drawing.Point(0, 0)); 
pictureBox1.Image = bitmap; 

,它爲我工作得很好。試着挑一個對比的刷子。

+0

是的,它做到了。非常感謝。 – 2011-03-03 21:43:50

4

你沒有更新你原來的代碼圖片(LabelImage),那麼爲什麼要添加到Graphics對象的文本顯示?

從MSDN,Graphics.FromImage

創建一個從指定圖像的圖形。

(重點煤礦)

已添加的文本後,您需要保存的更改:

graphic.Save(); 

無關你的問題,你應該把創建using聲明中的Graphics對象,以確保正確處置:

using(Graphics graphic = Graphics.FromImage(LabelImage)) 
{ 
    // use graphic here 
}