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

C#转换图片文件格式

编程学习2012-10-1138150

用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语言还会教给你更多的关于计算机的知识。它能给我们提供的裨益,简单列举如下:   1)相比较其他的编程语言(像C++,JAVA),C语言是个低级语言。从总体上来说,低级的编程语言可以让你更好的了解计算机。   2)设备驱动程序和操作系统只能用C语言来编写。现在,你...

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

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

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

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

常用asp函数

常用asp函数

<% '------------------------------------- '所有功能函数名如下: ' StrLength(str) 取得字符串长度 ' CutStr(str,strlen) 字符串长度切割 ' CheckIsEmpty(tstr) 检测是否为空 ' isInteger(para) 整数检验 ' CheckName(str) 名字字符校验 ' CheckPassword(str) 密码检验 ' CheckEmail(emai...

发表评论

访客

看不清,换一张

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