我有代碼在Winforms應用程序的圖片框上繪製圖像,我想知道是否有清除單個圖像而不是清除所有內容的方法。Graphics.Clear給定的圖像? C#Winforms
public void DrawImage(Image img, Point pos)
{
if (GraphicsRenderer!=null)
{
GraphicsRenderer.DrawImage(img, pos);
}
}
DrawImage(Image.FromFile("image.png"), new Point(0, 0));
// then this to draw a rectangle
public void DrawRectangle(Rectangle rect, Pen pen)
{
if (GraphicsRenderer == null)
GraphicsRenderer = Renderer.CreateGraphics();
GraphicsRenderer.DrawRectangle(pen, rect);
}
DrawRectangle(new Rectangle(new Point(0, 0), new Size(40, 40)), Pens.Red);
// now how do i clear only the image?
任何幫助或洞察力的讚賞!
如果'Renderer'是一個'PictureBox',則不要操縱其上的圖形。 'PictureBox'用於顯示加載的靜態圖像。如果要在表單上繪製,只需創建一個空面板,然後在「OnPaint」事件中繪製圖形,並使用「e.Graphics」對象而不是使用「CreateGraphics」 '。 –