当前位置:首页 > 编程学习 > C#转换图片文件格式

C#转换图片文件格式

编程学习2012-10-1142700

用C#将图片转换为另一种格式的图像。


代码如下:


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("无法转换此格式!");
  }
}



http://www.apull.net/html/2012101114.html

扫描二维码推送至手机访问。

版权声明:本文由海阔天空发布,如需转载请注明出处。

本文链接:https://www.apull.net/html/2012101114.html

分享给朋友:

相关文章

关于学习编程和C语言

关于学习编程和C语言

关于学习编程和C语言  转自 开复网 Q:该怎么学习编程?  A:首先问你一个问题:你们在学校都学些什么课程? 问这个问题的原因是,我认为学校的计算机科学基础课很重要。如果你所在学校的课程设置合理,那你应该先把主要精力花在这些基础课上。很多学生看到基础理论就茫然,不知道这些图表,符号,甚至硬件的知识对将来的软件开发有什么用。用处大得很哪。比如,操作系统课里讲到的多线程的东西在系统编程里很有用。又比如,尽管你将来不会去涉及电脑的...

MD5加密VB版

MD5加密VB版

'MD5加密VB版 '调用方法:str=MD5("Apull",32),就能得到"Apull"的32位的MD5。 Private m_lOnBits(30) Private m_l2Power(30) Private Const BITS_TO_A_BYTE = 8 Private Const BYTES_TO_A_WORD = 4 Private Const BITS_TO_A_WORD = 32 Private Fu...

 C++ string类常用函数

C++ string类常用函数

string类的构造函数:string(const char *s);    //用c字符串s初始化 string(int n,char  c);     //用n个字符c初始化此外,string类还支持默认构造函数和复制构造函数,如string s1;string  s2="hello";都是正确的写法。...

VB连接SQLServer数据库操作代码

VB连接SQLServer数据库操作代码

第一步,在ModConString模块中定义一系列变量'定义一个属性过程反映连接字符串Public Property Get conString() As Variant conString = "data source=.;initial catalog=Sims_four;user End Property'定义一个提供者反映数据库类型Public Property Get conProvide() As Variant co...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。