2014-01-10 44 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); 
    } 
}