tgu*_*clu 10 .net c# picturebox
PictureBox我的Windows窗体应用程序上有一个.
我在其中加载了一张图片,并Paint在代码中启用了该事件.它绘制一个矩形.
像这样:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics gr = e.Graphics;
Pen p = new Pen(Color.Red);
p.Width = 5.0f;
gr.DrawRectangle(p, 1, 2, 30, 40);
}
Run Code Online (Sandbox Code Playgroud)
然后我点击"保存"按钮:
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image.Save(@"C:\Documents and Settings\tr1g3800\Desktop\WALKING\30P\100000test.jpg",ImageFormat.Jpeg);
}
Run Code Online (Sandbox Code Playgroud)
但是保存的文件永远不会包含我绘制的矩形.
有谁有想法吗?
谢谢.你们的帮助都很有帮助.这很有效
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation=@"C:\Documents and Settings\tr1g3800\Desktop\WALKING\30P\100000.jpg" ;
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image.Save(@"C:\Documents and Settings\tr1g3800\Desktop\WALKING\30P\100000test.jpg",ImageFormat.Jpeg);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.Image);
Graphics gr = Graphics.FromImage(bmp);
Pen p = new Pen(Color.Red);
p.Width = 5.0f;
gr.DrawRectangle(p, 1, 2, 30, 40);
pictureBox1.Image = bmp;
}
Run Code Online (Sandbox Code Playgroud)