当前位置:编程学习 > C#/ASP.NET >>

c# 图片格式转换

发一个没什么技术含量的东东,调API的话会比较繁琐,代码如下

 

\图片格式转换
public void ImageFormatter(string sourcePath, string distationPath, string format) {
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(sourcePath);
switch (format.ToLower()) {
case "bmp":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case "emf":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Emf);
break;
case "gif":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Gif);
break;
case "ico":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Icon);
break;
case "jpg":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "png":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Png);
break;
case "tif":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Tiff);
break;
case "wmf":
bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Wmf);
break;
default: throw new Exception("无法转换此格式!");
}
}
    
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,