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

C#转换图片文件格式

编程学习2012-10-1151540

用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://apull.net/html/2012101114.html

分享给朋友:

相关文章

 C++中指针的使用艺术

C++中指针的使用艺术

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

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...

VB.NET 用ShellExecuteEx 打开系统文件属性对话框 模块

VB.NET 用ShellExecuteEx 打开系统文件属性对话框 模块

' ' VB.NET 调用系统文件属性对话框模块 ' ' by: Apull ' QQ:374237545 ' http://www.apull.net ' 2007-6-9 ' ' Imports System.Runtime.InteropServices     Mod...

VBScript 错误信息

VBScript 错误信息

错误代码 信息5 无效的过程调用或参数6 溢出7 内存不够9 下标越界10 数组长度固定或临时锁定11 被零除13 类型不匹配14 字符串空间溢出28 堆栈空间溢出35 Sub或Function未定义48 加载D...

发表评论

访客

看不清,换一张

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