Skip to main content
 首页 » 编程设计

c#之文本不显示在 C# 中的位图图像上

2024年02月23日13freeliver54

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

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

请您参考如下方法:

您没有更新原始图像 (LabelImage),那么为什么要显示添加到 Graphics 对象的文本?

来自 MSDN,Graphics.FromImage :

Creates a new Graphics from the specified Image.

(强调我的)

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

graphic.Save(); 

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

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