正如标题所示,您的主要问题是对什么是(常见的)误解Graphics
对象是。
到目前为止,我可以毫无问题地绘制我的图形对象
No! A 'Graphics
' 对象确实not包含any图形。这只是tool用于将图形绘制到related Bitmap
. So 你不画 the Graphics
完全反对;你用它来绘制imageRxTx
,无论那是什么,可能是某些事物的表面Control
or Form
..
该行使用了一种经常令人困惑且无用的格式Bitmap
构造函数 https://msdn.microsoft.com/de-de/library/byca5y1f%28v=vs.110%29.aspx:
Bitmap bmp = new Bitmap(image_RxTx.Width, image_RxTx.Height, Draw);
最后一个参数正在做几乎什么都没有;它唯一的功能就是复制Dpi
环境。特别是,它不会克隆或复制“Draw”中的任何内容,正如您现在所知,“Draw”是一个Graphics
对象无论如何都没有,也没有任何其他设置。所以是的,bmp Bitmap
之后仍然是空的。
如果你想画进bmp
你需要使用Graphics
实际绑定到它的对象:
using (Graphics G = Graphics.FromImage(bmp)
{
// draw now..
// to draw an Image img onto the Bitmap use
G.DrawImage(img, ...);
// with the right params for source and destination!
}
None这可能应该发生在Paint
事件!但所有的准备代码是unclear至于你真正想做的事情。你应该解释一下绘图的来源是什么,目标是什么!
如果你想得到你画的东西onto image_RxTx
into a Bitmap
你可以使用这个方法外面的某个地方(!) the Paint
event:
Bitmap bmp = new Bitmap(image_RxTx.Width, image_RxTx.Height);
image_RxTx.DrawToBitmap(bmp, image_RxTx.ClientRectangle);
这会use the Paint
将控件绘制到的事件Bitmap
。并不是说结果包括whole PictureBox
: The BackgroundImage
, the Image
and表面图!
Update: 为了得到combined的内容PictureBox
,这既是它的Image
以及您在表面上绘制的内容,您应该在Tick
的事件Timer
or就在触发的行之后Paint
事件。 (你没有向我们展示这是如何发生的。)你实际上不能把它放在Paint
事件本身,因为它将使用Paint
事件,因此会导致无限循环!