如何在C#中重置图片框中的图像 [英] How to reset the image in a picture box in C#
问题描述
大家好,
我想重置我在图片框中加载的图片,
实际上,我正在图像上绘制两个不同的图形,我想在第一个图形情节的另一个时刻第二个图形情节和前一个图形被删除。
这可以通过复选框完成
我该怎么办?
我的尝试:
我不是很擅长处理C#中的图形。
这是我的代码块我试图做的
private void checkBox1_CheckedChanged(object sender,EventArgs e)
{
if(checkBox1.Checked)
{
F = 1;
g.FillRectangle(Brushes.Red,Convert.ToInt32(x),Convert.ToInt32(y),9,9);
System.Threading.Thread.Sleep(50);
}
其他
{
F = 0;
initializePictureBox(Image);
g.FillRectangle(Brushes.Blue,Convert.ToInt32(x),Convert.ToInt32(y),9,9);
}
猜测,没有看到任何代码,或者你的意思是重置,这个可能是你想要的:
pictureBox1.Image = null ;
如果你的意思是清除任何绘制的图像,那么可能这样:
Graphics graphic = Graphics.fromimage(pictureBox1.Image);
graphic.Clear(Color.Red) // 填充背景并重置框的颜色
不是说它应该是必需的,但你可能需要强制更新:
pictureBox1。 Image.Refresh();
但这取决于你如何设置图像。你可能还需要这个:
pictureBox1.InitialImage = null ;
Hi every one,
I want to reset the image which I load it in a picture box,
Actually, I am plotting two different graphics on an image, I want to do like at first one graphic plot at another moment second graphic plot and the previous graphic become deleted.
This could be done through check box
How can I do it?
What I have tried:
I am not very good at dealing with graphics in C#
this is a block of my code which I tried to do
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked) { F = 1; g.FillRectangle(Brushes.Red, Convert.ToInt32(x), Convert.ToInt32(y), 9, 9); System.Threading.Thread.Sleep(50); } else { F = 0; initializePictureBox(Image); g.FillRectangle(Brushes.Blue, Convert.ToInt32(x), Convert.ToInt32(y), 9, 9); }
At a guess, without seeing any code, or what you mean by reset, this may be what you want:
pictureBox1.Image = null;
If you mean clear any images drawn, then maybe this:
Graphics graphic = Graphics.fromimage(pictureBox1.Image); graphic.Clear(Color.Red)//Color to fill the background and reset the box
Not that it should be required, but you may need to force an update:
pictureBox1.Image.Refresh();
But it depends on how you set the image. You may also need this:
pictureBox1.InitialImage = null;
这篇关于如何在C#中重置图片框中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!