Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用变量名保存位图图像_C#_Windows_Visual Studio_Bitmap - Fatal编程技术网

C# 无法使用变量名保存位图图像

C# 无法使用变量名保存位图图像,c#,windows,visual-studio,bitmap,C#,Windows,Visual Studio,Bitmap,我是C#的新手,我正试图在点击按钮时保存位图图像。我正在使用VisualStudio2010进行此操作。我可以保存我的图像,我传递一个特定的字符串作为文件名。以下是我保存图像的代码:- private void button1_Click(object sender, EventArgs e) { bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen

我是C#的新手,我正试图在点击按钮时保存位图图像。我正在使用VisualStudio2010进行此操作。我可以保存我的图像,我传递一个特定的字符串作为文件名。以下是我保存图像的代码:-

    private void button1_Click(object sender, EventArgs e)
    { 

        bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
        gfxScreenshot = Graphics.FromImage(bmpScreenshot);
        gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
        bmpScreenshot.Save("img.jpg", ImageFormat.Jpeg);
    }
但我想把这张照片保存为拍摄时的名字。因此,我在代码中添加了以下内容:-

    private void button1_Click(object sender, EventArgs e)
    { 
        string time = DateTime.Now.ToString("hh:mm:ss");
        string img = time + ".jpg";
        bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
        gfxScreenshot = Graphics.FromImage(bmpScreenshot);
        gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
        bmpScreenshot.Save(img, ImageFormat.Jpeg);

    }
这段代码构建得很好,但当我单击我的按钮时,出现了以下异常:-

NotSupportedException was handled

谁能告诉我如何将我的图像名称保存为timecode。

文件名不应包含
。尝试将其更改为下划线或仅删除它:

private void button1_Click(object sender, EventArgs e)
{ 
    string time = DateTime.Now.ToString("HHmmss");
    string img = time + ".jpg";
    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
    bmpScreenshot.Save(img, ImageFormat.Jpeg);

}

你不能把
放在文件名里谢谢你,老兄,我被困在里面超过两个小时了。