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

C#转换图片文件格式

编程学习2012-10-1156670

用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

分享给朋友:

相关文章

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

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

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

C++实现十进制转换为二进制

C++实现十进制转换为二进制

这个写得有些早了,学习c++是写的。现在看到很多帖子问这个问题,把这个贴上来供大家参考下。/* * FileName: bin.cpp * * 转换十进制为二进制 * * Apull * 2005-12-2 */ #include <iostream> #include <cstdlib> using namespace std; const int size = sizeof(int) *...

用VB类实现文件对话框

用VB类实现文件对话框

用VB类实现文件对话框'类名:ComDlg.cls '作用:文件打开保存对话框 ' ' ' 'By:Apull '2007-5-21 'http://www.apull.net Option Explicit Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" ( _ pOpenfil...

常用asp函数

常用asp函数

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