2014-01-10 42 views
3

我有下面的代码,我希望它保存为jpeg文件格式,而不是bmp。修改代码保存为jpeg

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,但没有奏效。

+0

微软文档这口井,结合实例http://msdn.microsoft.com/en-us/library/ytz20d80%28v=vs.110%29.aspx – Hogan

+0

您是否尝试过使用简单'.jpg'作为文件扩展名? –

回答

3

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