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

C#转换图片文件格式

编程学习2012-10-1155620

用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语言很多人对学习C语言感到无从下手,经常问我同一个问题:究竟怎样学习C语言?我是一个教师,已经开发了很多年的程序,和很多刚刚起步的人一样,学习的第一个计算机语言就是C语言。经过这些年的开发,我深深的体会到C语言对于一个程序设计人员多么的重要,如果不懂C语言,你想写底层程序这几乎听起来很可笑,不懂C语言,你想写出优秀高效的程序,这简直就是天方夜谭。为什么C语言如此重要呢?第一:C语言语法结构很简洁精妙,写出的程序也很高效,很便于描述算法,大多数的程序员愿意使用C语言去...

VB获取光驱盘符

VB获取光驱盘符

VB获取光驱盘符Option Explicit Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _ (ByVal nDrive As String) As Long 'GetLogicalDriveStrings-->获取一个字串,其中包含了当前所有逻辑驱动器的根驱动器路径 Private Declare Function GetLogicalDriveStri...

 C++中指针的使用艺术

C++中指针的使用艺术

C++中指针的使用艺术 在C++编程中使用指针能有速度快,节约内存等优点,是很多C++程序员的最爱。但指针是一把双刃剑,用好了它,你就会发现指针有多么的方便,反之,你可能就头疼了,往往会出现意想不到的问题。   一.什么是指针:   其实指针就像是其它变量一样,所不同的是一般的变量包含的是实际的真实的数据,而指针只是一个指示器,它告诉程序在内存的哪块区域可以找到数据。   这是一个非常重要的概念,有很多程序和算法都是围绕指针设计的,如链...

 C++ string类常用函数

C++ string类常用函数

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