Am developing a paint application in C# , VS2010
The start-up interface is a blank pictureBox ,
I did a mouseDown and a mouseMove event Handler for brush tool paint
and it works fine
When i try to save the new picture (After painting on the blank pictureBox) I enter the file , and it's only a blank picture.
The problem is that the code is not saving the effects.
why?
mouseDown event handler
private void mouseDown(object sender, MouseEventArgs e)
{
if (CurrentFunction == "DrawFree")
{
if (e.Button == MouseButtons.Left)
ReleaseFlag = true;
StartPoint = e.Location;
}
}
mouseMove event handler
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;
}
}
Save code
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);
}
}