我有代码在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” '。 –