c# - 修改代码保存为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)
            {
                current.Save(sfd.FileName);
            }
        }

        current.Dispose();
    }

你知道我应该改变什么来实现它吗?我尝试使用 Image.Format,但没有用。

最佳答案

要将 BitMap 对象保存为 JPG,只需在保存方法中指定 ImageFormat

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

关于c# - 修改代码保存为jpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21055391/

相关文章:

c# - ASP HttpClient GetAsync 没有响应,也没有超时

C# 如何为 jpeg 图像添加水印?

c# - 这是从 DataContext 更新实体的最佳方式吗?

javascript - 使用 AJAX 调用在 javascript 中下载文件

c# - 将位图转换为 8bpp 灰度输出作为 c# 中的 8bpp 彩色索引

java - 带有圆角的 AppWidget 图像

android - 位图回收不适用于 android 4.2 或更高版本的 4.2?

php - 处理大图像

iphone - iphone 中的 jpg 图像和 2x 图像

c# - 程序集中类的顺序