【问题标题】:Modify code to save as jpeg [duplicate]修改代码以另存为jpeg [重复]
【发布时间】:2014-01-10 22:12:29
【问题描述】:

我有下面的代码,我想让它保存为 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,但这不起作用。

【问题讨论】:

标签: c# bitmap jpeg


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-04-12
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 2012-11-03
    相关资源
    最近更新 更多