画图程序不保存编辑过的图片
本文关键字:编辑 保存 程序 | 更新日期: 2023-09-27 18:10:32
我正在用c#, VS2010开发一个绘图应用程序
启动界面为空白pictureBox
,我为画笔工具油漆做了mouseDown
和mouseMove
事件处理程序它运行良好
当我尝试保存新图片时(在空白pictureBox上绘制后)我输入文件,它只是一张空白图片。
问题是代码没有保存效果。
为什么?
mouseDown事件处理程序
private void mouseDown(object sender, MouseEventArgs e)
{
if (CurrentFunction == "DrawFree")
{
if (e.Button == MouseButtons.Left)
ReleaseFlag = true;
StartPoint = e.Location;
}
}
mouseMove事件处理程序
private void mouseMove(object sender, MouseEventArgs e)
{
if (CurrentFunction == "DrawFree")
{
if (ReleaseFlag)
{
EndPoint = e.Location;
g = pictureBox1.CreateGraphics();
g.DrawLine(p, StartPoint, EndPoint);
}
StartPoint = EndPoint;
}
}
<<p> 保存代码/strong> private void savePhotoToolStripMenuItem_Click(object sender, EventArgs e)
{
using (Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width,
pictureBox1.ClientSize.Height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
Image yourImage = pictureBox1.Image;
Bitmap yourBitmap = new Bitmap(yourImage);
g.DrawImage(yourBitmap,
new Rectangle(0, 0, bmp.Width, bmp.Height),
new Rectangle(0, 0, yourImage.Width, yourImage.Height),
GraphicsUnit.Pixel);
}
bmp.Save(@"d:'yourfile.png", ImageFormat.Png);
}
}
既然您的bitmap "yourBitmap"与您的图像,尝试替换bmp。保存您的位图。保存
yourBitmap.Image.Save(@"d:'yourfile.png", ImageFormat.Png);