據我所知,你實際上有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