C# 修改代码以另存为jpeg
我有下面的代码,我想让它保存为jpeg文件格式,而不是bmpC# 修改代码以另存为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)
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
作为文件扩展名?