C#中图像格式转换方法
下面是C#中图像格式转换的函数
本文为
中国ASP.NET开发网原创,转载请注明出处。
/// <summary>
/// 图形格式转换函数
/// </summary>
/// <param name="srcFile">源文件</param>
/// <param name="objFile">目标文件</param>
/// <param name="objFormat">目标文件格式</param>
public static void ImageFormatConvet(string srcFile, string objFile, System.Drawing.Imaging.ImageFormat objFormat)
{
System.IO.FileStream stream = System.IO.File.OpenRead(srcFile);
Bitmap bmp = new Bitmap(stream);
//得到原图
System.Drawing.Image image = bmp;
//创建指定大小的图
System.Drawing.Image newImage = image.GetThumbnailImage(bmp.Width, bmp.Height, null, new IntPtr());
Graphics g = Graphics.FromImage(newImage);
//将原图画到指定的图上
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
g.Dispose();
stream.Close();
//保存文件
newImage.Save(objFile, objFormat);
}
调用方法:
string fileName1 = @"D:\123.tif";
string fileName2 = @"D:\123-2.jpg";
ImageFormatConvet(fileName1, fileName2, System.Drawing.Imaging.ImageFormat.Jpeg);
本文为
中国ASP.NET开发网原创,转载请注明出处。