C# Image图片格式转换(gif/jpg/png/bmp)
C# 全选
/// <summary>
/// C# Image图片格式转换(gif/jpg/png/bmp)
/// </summary>
/// <param name="img"></param>
/// <param name="filePath"></param>
/// <returns></returns>
public bool SaveJpeg(Image img, string filePath)
{
try
{
using (var bmp = new Bitmap(img.Width, img.Height))
{
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
using (var g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
g.DrawImageUnscaled(img, 0, 0);
}
//存储各种格式
//bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Gif);
//bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
return true;
}
catch
{
return false;
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网