【问题标题】:paint program not saving edited picture绘画程序不保存编辑的图片
【发布时间】:2014-06-28 05:51:42
【问题描述】:

我正在用 C# VS2010 开发一个绘图应用程序

启动界面为空白pictureBox, 我为画笔工具绘制做了一个mouseDown 和一个mouseMove 事件处理程序 而且效果很好

当我尝试保存新图片时(在空白图片框上绘画后) 我输入文件,它只是一张空白图片。

问题是代码没有保存效果。

为什么?

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;
        }

    }

保存代码

 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);
        }
    }

【问题讨论】:

    标签: c# image paint


    【解决方案1】:

    由于您使用 yourImage 位图“yourBitmap”,请尝试将 bmp.Save 替换为 yourBitmap.Save

        yourBitmap.Image.Save(@"d:\yourfile.png", ImageFormat.Png);
    

    【讨论】:

    • 静止,空白图片
    • 我刚刚编辑了对“yourBitmap”的回答,更改后是否仍为空白?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多