資源簡介
實現了打開圖像、保存圖像、關閉以及通過提取像素法、內存法、指針法實現彩色圖像的灰度化

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
//using?System.Drawing.Drawing2D;
namespace?gray
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????????myTimer?=?new?HiPerfTimer();
????????}
????????private?void?open_Click(object?sender?EventArgs?e)
????????{
????????????OpenFileDialog?opnDlg?=?new?OpenFileDialog();
????????????opnDlg.Filter?=?“所有圖像文件?|?*.bmp;?*.pcx;?*.png;?*.jpg;?*.gif;“+?
????????????????“*.tif;?*.ico;?*.dxf;?*.cgm;?*.cdr;?*.wmf;?*.eps;?*.emf|“?+
????????????????“位圖(?*.bmp;?*.jpg;?*.png;...)?|?*.bmp;?*.pcx;?*.png;?*.jpg;?*.gif;?*.tif;?*.ico|“?+
????????????????“矢量圖(?*.wmf;?*.eps;?*.emf;...)?|?*.dxf;?*.cgm;?*.cdr;?*.wmf;?*.eps;?*.emf“;
????????????opnDlg.title?=?“打開圖像文件“;
????????????opnDlg.ShowHelp?=?true;
????????????if?(opnDlg.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????curFileName?=?opnDlg.FileName;
????????????????try
????????????????{
????????????????????curBitmap?=?(Bitmap)Image.FromFile(curFileName);
????????????????}
????????????????catch?(Exception?exp)
????????????????{
????????????????????MessageBox.Show(exp.Message);
????????????????}
????????????}
????????????Invalidate();
????????}
????????private?void?save_Click(object?sender?EventArgs?e)
????????{
????????????if(curBitmap?==?null)
????????????{
????????????????return;
????????????}
????????????SaveFileDialog?saveDlg?=?new?SaveFileDialog();
????????????saveDlg.title?=?“保存為“;
????????????saveDlg.OverwritePrompt?=?true;
????????????saveDlg.Filter?=
????????????????“BMP文件?(*.bmp)?|?*.bmp|“?+
????????????????“Gif文件?(*.gif)?|?*.gif|“?+
????????????????“JPEG文件?(*.jpg)?|?*.jpg|“?+
????????????????“PNG文件?(*.png)?|?*.png“;
????????????saveDlg.ShowHelp?=?true;
????????????if(saveDlg.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????string?fileName?=?saveDlg.FileName;
????????????????string?strFilExtn?=?fileName.Remove(0?fileName.Length?-?3);
????????????????switch?(strFilExtn)
????????????????{
????????????????????case?“bmp“:
????????????????????????curBitmap.Save(fileName?System.Drawing.Imaging.ImageFormat.Bmp);
????????????????????????break;
????????????????????case?“jpg“:
????????????????????????curBitmap.Save(fileName?System.Drawing.Imaging.ImageFormat.Jpeg);
????????????????????????break;
????????????????????case?“gif“:
????????????????????????curBitmap.Save(fileName?System.Drawing.Imaging.ImageFormat.Gif);
????????????????????????break;
????????????????????case?“tif“:
????????????????????????curBitmap.Save(fileName?System.Drawing.Imaging.ImageFormat.Tiff);
????????????????????????break;
????????????????????case?“png“:
????????????????????????curBitmap.Save(fileName?System.Drawing.Imaging.ImageFormat.Png);
????????????????????????break;
????????????????????default
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7083??2008-09-05?10:06??gray\Backup\gray\Form1.cs
?????文件???????6328??2008-09-05?10:06??gray\Backup\gray\Form1.Designer.cs
?????文件???????5814??2007-08-31?15:37??gray\Backup\gray\Form1.resx
?????文件???????3306??2007-08-31?14:47??gray\Backup\gray\gray.csproj
?????文件???????1548??2008-08-16?19:57??gray\Backup\gray\HiPerfTimer.cs
?????文件????????463??2007-08-30?15:10??gray\Backup\gray\Program.cs
?????文件???????1180??2007-08-30?15:10??gray\Backup\gray\Properties\AssemblyInfo.cs
?????文件???????2863??2007-08-30?15:10??gray\Backup\gray\Properties\Resources.Designer.cs
?????文件???????5612??2007-08-30?15:10??gray\Backup\gray\Properties\Resources.resx
?????文件???????1088??2007-08-30?15:10??gray\Backup\gray\Properties\Settings.Designer.cs
?????文件????????249??2007-08-30?15:10??gray\Backup\gray\Properties\Settings.settings
?????文件????????901??2007-08-30?15:10??gray\Backup\gray.sln
????..A..H.?????16384??2008-09-05?10:08??gray\Backup\gray.suo
?????文件??????14336??2014-12-10?14:32??gray\gray\bin\Debug\gray.exe
?????文件??????42496??2014-12-10?14:32??gray\gray\bin\Debug\gray.pdb
?????文件??????14328??2014-12-10?14:33??gray\gray\bin\Debug\gray.vshost.exe
?????文件????????490??2007-07-21?02:33??gray\gray\bin\Debug\gray.vshost.exe.manifest
?????文件???????7083??2008-09-05?10:06??gray\gray\Form1.cs
?????文件???????6328??2008-09-05?10:06??gray\gray\Form1.Designer.cs
?????文件???????5814??2007-08-31?15:37??gray\gray\Form1.resx
?????文件???????3514??2014-12-10?14:32??gray\gray\gray.csproj
?????文件???????1548??2008-08-16?19:57??gray\gray\HiPerfTimer.cs
?????文件????????503??2014-12-10?14:33??gray\gray\obj\Debug\gray.csproj.FileListAbsolute.txt
?????文件????????774??2014-12-10?14:32??gray\gray\obj\Debug\gray.csproj.GenerateResource.Cache
?????文件??????14336??2014-12-10?14:32??gray\gray\obj\Debug\gray.exe
?????文件????????180??2014-12-10?14:32??gray\gray\obj\Debug\gray.Form1.resources
?????文件??????42496??2014-12-10?14:32??gray\gray\obj\Debug\gray.pdb
?????文件????????180??2014-12-10?14:32??gray\gray\obj\Debug\gray.Properties.Resources.resources
?????文件???????4608??2014-12-10?14:32??gray\gray\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????247??2007-09-02?14:51??gray\gray\obj\gray.csproj.FileList.txt
............此處省略30個文件信息
- 上一篇:C#圖形學-線段裁剪
- 下一篇:C# 不使用Task實現的多線程順序執行
評論
共有 條評論