0

我试图简单地将我的资源文件夹中的图像绘制到 Windows 窗体上,但由于某种原因它没有显示出来,这是我试图使用的代码......我一直在阅读和搜索一段时间图形类和 C# 中的绘图,我似乎无法很好地理解它......任何帮助或评论都非常感谢

Bitmap bmp = new Bitmap(WindowsFormsApplication1.Properties.Resources.BoostNeddleTest);
Graphics m_graphics = Graphics.FromImage(bmp);
m_graphics.DrawImage(bmp, 100, 100);

图像没有被绘制,我不完全确定为什么。

4

2 回答 2

0

你可以做这样的事情 VRKnight

protected override void OnPaint(PaintEventArgs e)
{
   Bitmap bmp = new Bitmap(WindowsFormsApplication1.Properties.Resources.BoostNeddleTest);
   // Draw using this   
   e.Graphics.DrawImage(bmp,100,100);
   base.OnPaint(e);
}

您可以在此处阅读有关 OnPait Override 的更多信息 Overriding the OnPaint Method

于 2013-01-15T14:53:35.113 回答
0

对象的工作方式Graphics是这样的:-

 destination.DrawImage (source, position, etc...)

在您的代码中,目标与源相同!你m_graphics需要一个显示设备(屏幕或打印机),Graphics你需要使用的对象在 WinForm 的 OnPaint 方法中给你。

于 2013-01-15T14:53:53.610 回答