文本未在C#中的位图图像上显示

时间:2011-03-03 21:02:03

标签: c# image text

我似乎无法得到我写的文字显示在我的图像上这是我正在使用的代码

//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

2 个答案:

答案 0 :(得分:4)

您没有更新原始图片(LabelImage),那么为什么您添加到Graphics对象的文字会显示?。

来自MSDN,Graphics.FromImage

  

从指定的图像创建图形。

(强调我的)

添加完文本后,您需要保存更改:

graphic.Save();

与您的问题无关,您应该将Graphics对象的创建放在using语句中,以确保正确处置:

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

答案 1 :(得分: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;

它对我来说很好。只是尝试选择对比鲜明的刷子。