开发者

C# Save Pitcherbox1 by Button1 in .png

I have been trying t开发者_运维技巧o save the image in pictureBox1. What am trying to do is to make it so people can "Save" the image from pictureBox1 by clicking on my "Save As" Button.

I am using Visual Studio 2010 with C#

This is what I have so far:

    private void Button2_Click(System.Object sender, System.EventArgs e)
    {

        SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        saveFileDialog1.Filter = "Png Image|*.jpg";
        saveFileDialog1.Title = "Save an Image File";
        saveFileDialog1.ShowDialog();
        if (saveFileDialog1.FileName != "")
        pictureBox1.Image = new Bitmap ("c:/avatar.png");
        {
            SaveFileDialog dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image.Save(@"C:\Documents and Settings\.Png", System.Drawing.Imaging.ImageFormat.Png);
            }
        }
    }


I'm not sure what you are trying with your code, there seems to be quite a few things wrong in there. This is how I would do it:

private void Button2_Click(System.Object sender, System.EventArgs e)
{
    if (pictureBox.Image != null)
    {
        using {var dialog = new SaveFileDialog())
        {
            dialog.Title = ...
            saveFileDialog1.Filter = "Png Image|*.png";
            ...other properties...

            if (dialog.ShowDialog == DialogResult.OK)
            {
                 pictureBox.Image.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Png)
            }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜