• 大小: 69KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: 灰度化  

资源简介

实现了打开图像、保存图像、关闭以及通过提取像素法、内存法、指针法实现彩色图像的灰度化

资源截图

代码片段和文件信息

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个文件信息

评论

共有 条评论