Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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# 修改代码以另存为jpeg_C#_Bitmap_Jpeg - Fatal编程技术网

C# 修改代码以另存为jpeg

C# 修改代码以另存为jpeg,c#,bitmap,jpeg,C#,Bitmap,Jpeg,我有下面的代码,我想让它保存为jpeg文件格式,而不是bmp Bitmap current = (Bitmap)_latestFrame.Clone(); using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "*.bmp|*.bmp"; if (sfd.ShowDialog() == DialogResult.OK)

我有下面的代码,我想让它保存为jpeg文件格式,而不是bmp

Bitmap current = (Bitmap)_latestFrame.Clone();
        using (SaveFileDialog sfd = new SaveFileDialog())
        {
            sfd.Filter = "*.bmp|*.bmp";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                current.Save(sfd.FileName);
            }
        }

        current.Dispose();
    }

你知道我应该做什么改变吗?我试过使用Image.Format,但没用

要将
位图
对象保存为JPG,只需在保存方法中指定
图像格式

currentSave(sdf.FileName, ImageFormat.Jpeg);
理想情况下,您可以根据用户选择的扩展来进行此操作。类似于下面的内容

sfd.Filter = "*.bmp|*.jpg:
if (sfd.ShowDialog() == DialogResult.OK) {
  if (sfd.FileName.EndsWith("jpg")) {
    current.Save(sfd.FileName, ImageFormat.Jpeg);
  } else { 
    current.Save(sfd.FileName);
  }
}

微软的文档记录得很好,举例来说,您是否尝试过简单地使用
.jpg
作为文件扩展名?