使用图纸保存面板C#

时间:2018-06-12 13:28:35

标签: c# image winforms save

对于一个小项目,我尝试创建一个"" Paint App"。

现在我想将这幅画保存为文件,遗憾的是,我的方法只会保存背景和我的手稿。

这就是我创建Panel和绘图方法的方法:

    private void panel1_Paint(object sender, PaintEventArgs e)  //Bild erstellen
    {
        Graphics g = panel1.CreateGraphics();

        Pen pen = new Pen(colorDialog1.Color);
        g.DrawEllipse(pen, pointx, pointy, width, height);
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e) //Linie malen
    {
        if (e.Button == MouseButtons.Left)
        {
            pointx = e.X;
            pointy = e.Y;
            panel1_Paint(this, null);
        }
    }

这就是我创建Bmp的方式:

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SaveFileDialog save = new SaveFileDialog();
        save.CheckFileExists = false;
        save.CheckPathExists = true;
        save.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
        save.InitialDirectory = @"C:\Users\";

        DialogResult result = save.ShowDialog();
        if (result == DialogResult.OK)
        {
            Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);

            panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));

            bmp.Save(save.FileName);

        }
    }

My output File looks like:

What is should look like:

感谢每一条建议:)

0 个答案:

没有答案