据我所知,你实际上有Rectangle
,现在想从你的油漆Panel
复制一个区域。
这是可能的,假设您已将所有绘画放在Panel
的Paint
事件中。
然后,您可以使用DrawToBitmap
来要求Panel
吸取新的Bitmap
;从那里,你可以DrawImage
的Rectangle
到您Panel
。
注意:为了与您的'Paint-Actions'列表集成,您必须现在存储该Bitmap
或存储Rectangle
并重做整个操作。
using (Graphics G = panelCanvas.CreateGraphics())
{
Rectangle R0 = new Rectangle(22,22,55,55); // your Rectangle!
using (Bitmap bmp = new
Bitmap(panelCanvas.ClientSize.Width, panelCanvas.ClientSize.Height))
{ panelCanvas.DrawToBitmap(bmp, panelCanvas.ClientRectangle);
G.DrawImage(bmp, 111f, 111f, R0, GraphicsUnit.Pixel);
}
}
旁白:请不要更换ArrayList
,这是由新List<T>
,例如depracated一个List<PaintAction>
或任何你的班级的名字!
如果你只是想提取从面板控制型矩形区域,您可以使用thsi功能:
public Bitmap getAreaFrom(Control ctl, Rectangle area)
{
Bitmap bmp2 = new Bitmap(area.Width, area.Height);
using (Graphics G = ctl.CreateGraphics())
using (Bitmap bmp = new Bitmap(ctl.ClientSize.Width, ctl.ClientSize.Height))
{
ctl.DrawToBitmap(bmp, ctl.ClientRectangle);
using (Graphics G2 = Graphics.FromImage(bmp2))
G2.DrawImage(bmp, 0f, 0f, area, GraphicsUnit.Pixel);
}
return bmp2;
}
来源
2014-09-02 06:25:41
TaW
这听起来像你写[一个“画”节目,而不是“画图”程序] (http://www.pcdon.com/deDrawingAndPaintingPrograms.html)。 MS Paint不会记住每个绘制的形状,它只是将该形状绘制到画布上,并记住画布。这就是为什么在最终完成后你无法移动矩形(你已经点击了)。如果采用相同的方法,矩形选择工具将更容易。 – Blorgbeard 2014-09-02 03:27:04