【问题标题】:text not showing on bitmap image in C#C#中的位图图像上未显示文本
【发布时间】:2011-03-03 21:02:02
【问题描述】:

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

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

【问题讨论】:

    标签: c# image text


    【解决方案1】:

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

    来自 MSDN,Graphics.FromImage

    从指定的图像创建一个新的图形。

    (强调我的)

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

    graphic.Save();
    

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

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

    【讨论】:

      【解决方案2】:

      我刚试过这个

       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;
      

      它对我来说很好用。试着选择一个对比鲜明的画笔。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-07
        相关资源
        最近更新 更多