PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序

PjConvertImageFormat,基本上将所有的FreeImage支持的文件格式都做上去了,也就是说你可以在35种图像格式之间相互转换,它们分别是:bmp/ico/jpeg/jpg/jng/koala/dds/exr/lbm/iff/mng/pbm/gif/j2k/pcd/pcx/pgm/png/hdr/jp2/ppm/ras/targa/tiff/g3/pfm/wbmp/psd/cut/xbm/xpm/sgi/pict图像格式之间相互转换的。

【网通】点击此处下载全部源程序              【电信、网通】点击此处下载全部源程序

【下载说明】
1、单击上面这个地址,打开下载页面。
2、点普通下载--等待30秒--点“下载”按钮--保存

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第1张图片

上图为初始化界面。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第2张图片

上图为打开一幅BMP图片之后的效果。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第3张图片

上图为Rescale选项窗口。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第4张图片

上图为RotateFlip选项窗口。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第5张图片

上图为adjust brightness调整亮度窗口

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第6张图片

上图为adjust contrast调整对比度窗口

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第7张图片

上图为adjust gamma调整伽马曲线窗口

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第8张图片

上图为bmp位图保存选项窗口。可以支持转换至1位、4位、8位、16位、24位和32位位图。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第9张图片

上图为jpeg图片保存选项窗口。可以选择jpeg编码的质量。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第10张图片

上图为exr图像文件的保存选项窗口。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第11张图片

上图png图像文件的保存选项窗口。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第12张图片

上图是tiff图像文件的保存选项窗口。

PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序_第13张图片

上图是关于对话框。

部分源程序如下:

/*
 * Created by SharpDevelop.
 * User: PJ
 * Date: 2012-9-18
 * Time: 10:06
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

using FreeImageAPI;

namespace ConvertImageFormat
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		private FreeImageBitmap bitmap = null;
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			this.toolTip1.SetToolTip(this.rbtnBmp,"Windows or OS/2 Bitmap File");
			this.toolTip1.SetToolTip(this.rbtnIco,"Windows Icon");
			this.toolTip1.SetToolTip(this.rbtnJpeg,"Independent JPEG Group");
			this.toolTip1.SetToolTip(this.rbtnJng,"JPEG Network Graphics");
			this.toolTip1.SetToolTip(this.rbtnKoala,"Commodore 64 Koala format");
			this.toolTip1.SetToolTip(this.rbtnIff,"Amiga IFF");
			this.toolTip1.SetToolTip(this.rbtnLbm,"Amiga IFF");
			this.toolTip1.SetToolTip(this.rbtnMng,"Multiple Network Graphics");
			this.toolTip1.SetToolTip(this.rbtnPbm,"Portable Bitmap(ASCII)");
			this.toolTip1.SetToolTip(this.rbtnPbmraw,"Portable Bitmap(BINARY)");
			this.toolTip1.SetToolTip(this.rbtnPcd,"Kodak PhotoCD");
			this.toolTip1.SetToolTip(this.rbtnPcx,"Zsoft Paintbrush PCX bitmap format");
			this.toolTip1.SetToolTip(this.rbtnPgm,"Portable Graymap(ASCII)");
			this.toolTip1.SetToolTip(this.rbtnPgmraw,"Portable Graymap(BINARY)");
			this.toolTip1.SetToolTip(this.rbtnPng,"Portable Network Graphics");
			this.toolTip1.SetToolTip(this.rbtnPpm,"Portable Pixelmap(ASCII)");
			this.toolTip1.SetToolTip(this.rbtnPpmraw,"Portable Pixelmap(BINARY)");
			this.toolTip1.SetToolTip(this.rbtnRas,"Sun Rasterfile");
			this.toolTip1.SetToolTip(this.rbtnTarga,"truevision Targa files");
			this.toolTip1.SetToolTip(this.rbtnTiff,"Tagged Image File Format");
			this.toolTip1.SetToolTip(this.rbtnWbmp,"Wireless Bitmap");
			this.toolTip1.SetToolTip(this.rbtnPsd,"Adobe Photoshop");
			this.toolTip1.SetToolTip(this.rbtnCut,"Dr.Halo");
			this.toolTip1.SetToolTip(this.rbtnXbm,"X11 Bitmap Foramt");
			this.toolTip1.SetToolTip(this.rbtnXpm,"X11 Pixmap Format");
			this.toolTip1.SetToolTip(this.rbtnDds,"DirectDraw Surface");
			this.toolTip1.SetToolTip(this.rbtnGif,"Graphics Interchange Format");
			this.toolTip1.SetToolTip(this.rbtnHdr,"High Dynamic Range");
			this.toolTip1.SetToolTip(this.rbtnFaxg3,"Raw Fax format CCITT G3");
			this.toolTip1.SetToolTip(this.rbtnSgi,"Silicon Graphics SGI image format");
			this.toolTip1.SetToolTip(this.rbtnExr,"OpenEXR format");
			this.toolTip1.SetToolTip(this.rbtnJ2k,"JPEG-2000 format");
			this.toolTip1.SetToolTip(this.rbtnJp2,"JPEG-2000 format");
			this.toolTip1.SetToolTip(this.rbtnPfm,"Portable FloatMap");
			this.toolTip1.SetToolTip(this.rbtnPict,"Macintosh PICT");
		}
		
		void BtnBrowserImgClick(object sender, EventArgs e)
		{
			OpenFileDialog ofd = new OpenFileDialog();
			ofd.Title = "Open a Image File";
			ofd.Filter = "Windows or OS/2 Bitmap File(*.bmp)|*.bmp"
					+ "|Windows Icon(*.ico)|*.ico"
					+ "|Independent JPEG Group(*.jpg;*.jif;*.jpeg;*.jpe)|*.jpg;*.jif;*.jpeg;*.jpe"
					+ "|JPEG Network Graphics(*.jng)|*.jng"
					+ "|Commodore 64 Koala format(*.koa)|*.koa"
					+ "|Amiga IFF(*.iff)|*.iff"
					+ "|Amiga IFF(*.lbm)|*.lbm"
					+ "|Multiple Network Graphics(*.mng)|*.mng"
					+ "|Portable Bitmap(ASCII)(*.pbm)|*.pbm"
					+ "|Portable Bitmap(BINARY)(*.pbm)|*.pbm"
					+ "|Kodak PhotoCD(*.pcd)|*.pcd"
					+ "|Zsoft Paintbrush PCX bitmap format(*.pcx)|*.pcx"
					+ "|Portable Graymap(ASCII)(*.pgm)|*.pgm"
					+ "|Portable Graymap(BINARY)(*.pgm)|*.pgm"
					+ "|Portable Network Graphics(*.png)|*.png"
					+ "|Portable Pixelmap(ASCII)(*.ppm)|*.ppm"
					+ "|Portable Pixelmap(BINARY)(*.ppm)|*.ppm"
					+ "|Sun Rasterfile(*.ras)|*.ras"
					+ "|truevision Targa files(*.tga;*.targa)|*.tga;*.targa"
					+ "|Tagged Image File Format(*.tif;*.tiff)|*.tif;*.tiff"
					+ "|Wireless Bitmap(*.wbmp)|*.wbmp"
					+ "|Adobe Photoshop(*.psd)|*.psd"
					+ "|Dr.Halo(*.cut)|*.cut"
					+ "|X11 Bitmap Foramt(*.xbm)|*.xbm"
					+ "|X11 Pixmap Format(*.xpm)|*.xpm"
					+ "|DirectDraw Surface(*.dds)|*.dds"
					+ "|Graphics Interchange Format(*.gif)|*.gif"
					+ "|High Dynamic Range(*.hdr)|*.hdr"
					+ "|Raw Fax format CCITT G3(*.g3)|*.g3"
					+ "|Silicon Graphics SGI image format(*.sgi)|*.sgi"
					+ "|OpenEXR format(*.exr)|*.exr"
					+ "|JPEG-2000 format(*.j2k;*.j2c)|*.j2k;*.j2c"
					+ "|JPEG-2000 format(*.jp2)|*.jp2"
					+ "|Portable FloatMap(*.pfm)|*.pfm"
					+ "|Macintosh PICT(*.pict)|*.pict";
			if(ofd.ShowDialog() == DialogResult.OK){
				this.bitmap = new FreeImageBitmap(Image.FromFile(ofd.FileName));
				
				this.pictureBox1.Image = Image.FromFile(ofd.FileName);
				this.tbxSrcImgPath.Text = ofd.FileName;
				
				this.textBox1.Text = "Width = " + this.bitmap.Width.ToString() + "\r\n"
					+ "Height = " + this.bitmap.Height.ToString() + "\r\n"
					+ "ImageFormat = " + this.bitmap.ImageFormat.ToString() + "\r\n"
					+ "ImageType = " + this.bitmap.ImageType.ToString() + "\r\n"
					+ "PixelFormat = " + this.bitmap.PixelFormat.ToString() + "\r\n"
					+ "ColorDepth = " + this.bitmap.ColorDepth.ToString() + "\r\n"
					+ "ColorUsed = " + this.bitmap.ColorsUsed.ToString() + "\r\n"
					+ "ColorType = " + this.bitmap.ColorType.ToString();
			}
		}
		
		void MainFormFormClosing(object sender, FormClosingEventArgs e)
		{
			if(this.bitmap != null)
				this.bitmap.Dispose();
		}
		
		string OpenSaveFileDialog(string filter){
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.Title = "Choose a place to save";
			sfd.Filter = filter;
			if(sfd.ShowDialog() == DialogResult.OK){
				return sfd.FileName;
			}else{
				return string.Empty;
			}
		}
		
		void BtnConvertClick(object sender, EventArgs e)
		{
			if(this.rbtnBmp.Checked){
				BmpForm bf = new BmpForm(this.bitmap);
				bf.ShowDialog();
			}
			
			if(this.rbtnIco.Checked){
				string path = OpenSaveFileDialog("ICO File(*.ico)|*.ico");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_ICO);
				}
			}
			
			if(this.rbtnJpeg.Checked){
				JpegForm jf = new JpegForm(this.bitmap);
				jf.ShowDialog();
			}
			
			if(this.rbtnJng.Checked){
				string path = OpenSaveFileDialog("JNG File(*.jng)|*.jng");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_JNG);
				}
			}
			
			if(this.rbtnDds.Checked){
				string path = OpenSaveFileDialog("DDS File(*.dds)|*.dds");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_DDS);
				}
			}
			
			if(this.rbtnKoala.Checked){
				string path = OpenSaveFileDialog("Koala File(*.koa)|*.koa");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_KOALA);
				}
			}
			
			if(this.rbtnExr.Checked){
				ExrForm ef = new ExrForm(this.bitmap);
				ef.ShowDialog();
			}
			
			if(this.rbtnLbm.Checked){
				string path = OpenSaveFileDialog("LBM File(*.lbm)|*.lbm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_LBM);
				}
			}
			
			if(this.rbtnPbm.Checked){
				string path = OpenSaveFileDialog("ASCII PBM File(*.pbm)|*.pbm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PBM);
				}
			}
			
			if(this.rbtnPbmraw.Checked){
				string path = OpenSaveFileDialog("Binary PBM File(*.pbm)|*.pbm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PBMRAW);
				}
			}
			
			if(this.rbtnIff.Checked){
				string path = OpenSaveFileDialog("IFF File(*.iff)|*.iff");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_IFF);
				}
			}
			
			if(this.rbtnMng.Checked){
				string path = OpenSaveFileDialog("MNG File(*.mng)|*.mng");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_MNG);
				}
			}
			
			if(this.rbtnGif.Checked){
				string path = OpenSaveFileDialog("Gif File(*.gif)|*.gif");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_GIF);
				}
			}
			
			if(this.rbtnJ2k.Checked){
				string path = OpenSaveFileDialog("J2K File(*.j2k)|*.j2k");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_MNG);
				}
			}
			
			if(this.rbtnPcd.Checked){
				string path = OpenSaveFileDialog("PCD File(*.pcd)|*.pcd");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_PCD);
				}
			}
			
			if(this.rbtnPcx.Checked){
				string path = OpenSaveFileDialog("PCX File(*.pcx)|*.pcx");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_PCX);
				}
			}
			
			if(this.rbtnPgm.Checked){
				string path = OpenSaveFileDialog("PGM ASCII File(*.pgm)|*.pgm");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_PGM);
				}
			}
			
			if(this.rbtnPgmraw.Checked){
				string path = OpenSaveFileDialog("PGM Binary File(*.pgm)|*.pgm");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_PGMRAW);
				}
			}
			
			if(this.rbtnPng.Checked){
				PngForm pf = new PngForm(this.bitmap);
				pf.ShowDialog();
			}
			
			if(this.rbtnHdr.Checked){
				string path = OpenSaveFileDialog("HDR Binary File(*.hdr)|*.hdr");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_HDR);
				}
			}
			
			if(this.rbtnJp2.Checked){
				string path = OpenSaveFileDialog("JP2 Binary File(*.jp2)|*.jp2");
				if(path != string.Empty){
					this.bitmap.Save(path,FREE_IMAGE_FORMAT.FIF_JP2);
				}
			}
			
			if(this.rbtnPpm.Checked){
				string path = OpenSaveFileDialog("PPM ASCII File(*.ppm)|*.ppm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PPM);
				}
			}
			
			if(this.rbtnPpmraw.Checked){
				string path = OpenSaveFileDialog("PPM Binary File(*.ppm)|*.ppm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PPMRAW);
				}
			}
			
			if(this.rbtnRas.Checked){
				string path = OpenSaveFileDialog("RAS File(*.ras)|*.ras");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_RAS);
				}
			}
			
			if(this.rbtnTarga.Checked){
				string path = OpenSaveFileDialog("Targa File(*.tga)|*.tga");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_TARGA);
				}
			}
			
			if(this.rbtnTiff.Checked){
				TiffForm tf = new TiffForm(this.bitmap);
				tf.ShowDialog();
			}
			
			if(this.rbtnFaxg3.Checked){
				string path = OpenSaveFileDialog("FAXG3 File(*.g3)|*.g3");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_FAXG3);
				}
			}
			
			if(this.rbtnPfm.Checked){
				string path = OpenSaveFileDialog("PFM File(*.pfm)|*.pfm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PFM);
				}
			}
			
			if(this.rbtnWbmp.Checked){
				string path = OpenSaveFileDialog("WBMP File(*.wbmp)|*.wbmp");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_WBMP);
				}
			}
			
			if(this.rbtnPsd.Checked){
				string path = OpenSaveFileDialog("PSD File(*.psd)|*.psd");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PSD);
				}
			}
			
			if(this.rbtnCut.Checked){
				string path = OpenSaveFileDialog("CUT File(*.cut)|*.cut");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_CUT);
				}
			}
			
			if(this.rbtnXbm.Checked){
				string path = OpenSaveFileDialog("XBM File(*.xbm)|*.xbm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_XBM);
				}
			}
			
			if(this.rbtnXpm.Checked){
				string path = OpenSaveFileDialog("XPM File(*.xpm)|*.xpm");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_XPM);
				}
			}
			
			if(this.rbtnSgi.Checked){
				string path = OpenSaveFileDialog("SGI File(*.sgi)|*.sgi");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_SGI);
				}
			}
			
			if(this.rbtnPict.Checked){
				string path = OpenSaveFileDialog("PICT File(*.pict)|*.pict");
				if(path != string.Empty){
					this.bitmap.Save(path, FREE_IMAGE_FORMAT.FIF_PICT);
				}
			}
		}
		
		void BtnExitClick(object sender, EventArgs e)
		{
			if(this.bitmap != null)
				this.bitmap.Dispose();
			
			this.Close();
		}
		
		void BtnRescaleClick(object sender, EventArgs e)
		{
			if(this.bitmap == null) return;
			
			RescaleForm rf = new RescaleForm();
			if(rf.ShowDialog() == DialogResult.OK){
				if(!this.bitmap.Rescale(rf.mWidth,rf.mHeight,rf.mFilter)){
					MessageBox.Show("Rescale image failed!!!","Error");
				}else{
					MessageBox.Show("Rescale image passed!!!","Info.");
					this.pictureBox1.Image = this.bitmap.ToBitmap();
				}
			}
		}
		
		void BtnRotateFlipClick(object sender, EventArgs e)
		{
			if(this.bitmap == null) return;
			
			RotateFlipForm rff = new RotateFlipForm();
			if(rff.ShowDialog() == DialogResult.OK){
				this.bitmap.RotateFlip(rff.type);
				MessageBox.Show("Rotate and Flip successfully.","Info.");
				this.pictureBox1.Image = this.bitmap.ToBitmap();
			}
		}
		
		void BtnAdjustBrightnessClick(object sender, EventArgs e)
		{
			if(this.bitmap == null) return;
			
			AdjustBrightnessForm adf = new AdjustBrightnessForm(this.bitmap);
			if(adf.ShowDialog() == DialogResult.OK){
				if(this.bitmap.AdjustBrightness(adf.percentage)){
					MessageBox.Show("Adjust Brightness successfully.","Info.");
					this.pictureBox1.Image = this.bitmap.ToBitmap();
				}else
					MessageBox.Show("Adjust Brightness failed.","Info.");
			}
		}
		
		void BtnAdjustContrastClick(object sender, EventArgs e)
		{
			if(this.bitmap == null) return;
			
			AdjustBrightnessForm adf = new AdjustBrightnessForm(this.bitmap,"Adjust Contrast",1);
			if(adf.ShowDialog() == DialogResult.OK){
				if(this.bitmap.AdjustContrast(adf.percentage)){
					MessageBox.Show("Adjust Contrast successfully.","Info");
					this.pictureBox1.Image = this.bitmap.ToBitmap();
				}else{
					MessageBox.Show("Adjust Contrast failed.","Info.");
				}
			}
		}
		
		void BtnAdjustGammaClick(object sender, EventArgs e)
		{
			if(this.bitmap == null) return;
			
			AdjustBrightnessForm adf = new AdjustBrightnessForm(this.bitmap,"Adjust Gamma",2,0,200);
			if(adf.ShowDialog() == DialogResult.OK){
				if(this.bitmap.AdjustGamma(adf.percentage)){
					MessageBox.Show("Adjust Gamma passed.","Info");
					this.pictureBox1.Image = this.bitmap.ToBitmap();
				}else{
					MessageBox.Show("Adjust Gamma failed.","Info");
				}
			}
		}
		
		void BtnAboutClick(object sender, EventArgs e)
		{
			string str="Author: PJ\r\n"
				+ "Email: [email protected]\r\n"
				+ "Blog: http://blog.csdn.net/pengqianhe";
			MessageBox.Show(str,"About");
		}
	}
}

【更多阅读】

  1. [原]GetAlpha:C#实现获取网页验证码图片,并识别出其中的字母
  2. [译]在C# .NET2.0实现单实例应用程序
  3. [原]PjCleanSystemTrash:C#清除系统盘垃圾
  4. [原]IniFile.cs:C#来操作ini配置文件
  5. [原]QQHelper:QQ大家来找茬 辅助工具 外挂
  6. [译]在C# .NET2.0实现单实例应用程序
  7. [原]GetAlpha:C#实现获取网页验证码图片,并识别出其中的字母
  8. [原]GetIcons:C#提取应用程序的图标资源
  9. [原]IniFile.cs:C#来操作ini配置文件
  10. [原]使用Excel的VBA来读取和修改bmp位图像素数据

点击此处下载全部PjConvertImageFormat源程序

你可能感兴趣的:(image,String,object,File,Path,NetWork)