• 大小: 50KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-19
  • 语言: C#
  • 标签: c#  bmp  

资源简介

c#图像处理(bmp转化为灰度图片),详细,简单,文件包有创建说明,相当详细。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace readbmp2
{
    public partial class Form1 : Form
    {

        void GrayMenuClick()
        {
            Bitmap bmp = new Bitmap(picBox.Image);
            Bitmap newbmp = new Bitmap(picBox.Image);
            Color c = new Color();
            Color NewC;
            Byte r g b gray;

            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    c = bmp.GetPixel(i j);
                    r = c.R;
                    g = c.G;
                    b = c.B;
                    gray = (Byte)((r * 19595 + g * 38469 + b * 7472) >> 16);
                    NewC = Color.FromArgb(gray gray gray);
                    newbmp.SetPixel(i j NewC);
                }
            }

            // 刷新显示
            picBox.Refresh();
            picBox.Image = newbmp;
        }
        void SaveMenuClick()
     {
          string filename;
         SaveFileDialog dlg=new SaveFileDialog();
          dlg.Filter=“JPG File(*.jpg)|*.jpg|Bmp File(*.bmp)|*.bmp|All Files(*.*)|*.*“;
          if (dlg.ShowDialog()== DialogResult.OK) {
              filename=dlg.FileName;
             if (picBox.Image!=null) {
                 picBox.Image.Save(filename);
             }
             else
             {
                MessageBox.Show(“没有图像可以保存!“);
             }
         }
     }


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {

            picBox.Location = new Point(30 30);
            picBox.Size = new Size(400 300);
            btnOpen.Location = new Point(30 350);
            button2.Location = new Point(180 350);
            button3.Location = new Point(310 350);
            
        }

        private void btnOpen_Click(object sender EventArgs e)
        {
            OpenFileDialog ofdPic = new OpenFileDialog();
            ofdPic.Filter = “JPG(*.JPG;*.JPEG);gif文件(*.GIF)|*.jpg;*.jpeg;*.gif“;
            ofdPic.FilterIndex = 1;
            ofdPic.RestoreDirectory = true;
            ofdPic.FileName = ““;
            if (ofdPic.ShowDialog() == DialogResult.OK)
            {
                string sPicPaht = ofdPic.FileName.ToString();
                FileInfo fiPicInfo = new FileInfo(sPicPaht);
                long lPicLong = fiPicInfo.Length / 1024;
                string sPicName = fiPicInfo.Name;
                string sPicDirectory = fiPicInfo.Directory.ToString();
                string sPicDirectoryPath = fiPicInfo.DirectoryName;
                Bitmap bmPic = new Bitmap(sPicPaht);
                //if (lPicLong > 400)
                //{
                // 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-06-11 10:49  readbmp2\
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\
     文件         866  2012-06-10 11:21  readbmp2\readbmp2.sln
     文件       18944  2012-06-11 10:39  readbmp2\readbmp2.suo
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\bin\
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\bin\Debug\
     文件       10752  2012-06-11 10:46  readbmp2\readbmp2\bin\Debug\readbmp2.exe
     文件       26112  2012-06-11 10:46  readbmp2\readbmp2\bin\Debug\readbmp2.pdb
     文件       11600  2012-06-11 10:46  readbmp2\readbmp2\bin\Debug\readbmp2.vshost.exe
     文件         490  2010-03-17 22:39  readbmp2\readbmp2\bin\Debug\readbmp2.vshost.exe.manifest
     文件        4094  2012-06-11 10:46  readbmp2\readbmp2\Form1.cs
     文件        4375  2012-06-11 10:43  readbmp2\readbmp2\Form1.Designer.cs
     文件        5817  2012-06-11 10:43  readbmp2\readbmp2\Form1.resx
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\obj\
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\obj\x86\
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\obj\x86\Debug\
     文件        4501  2012-06-10 18:10  readbmp2\readbmp2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6362  2012-06-11 10:46  readbmp2\readbmp2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         228  2012-06-11 10:43  readbmp2\readbmp2\obj\x86\Debug\GenerateResource.read.1.tlog
     文件         558  2012-06-11 10:43  readbmp2\readbmp2\obj\x86\Debug\GenerateResource.write.1.tlog
     文件         892  2012-06-11 10:46  readbmp2\readbmp2\obj\x86\Debug\readbmp2.csproj.FileListAbsolute.txt
     文件       10752  2012-06-11 10:46  readbmp2\readbmp2\obj\x86\Debug\readbmp2.exe
     文件         180  2012-06-11 10:43  readbmp2\readbmp2\obj\x86\Debug\readbmp2.Form1.resources
     文件       26112  2012-06-11 10:46  readbmp2\readbmp2\obj\x86\Debug\readbmp2.pdb
     文件         180  2012-06-10 18:32  readbmp2\readbmp2\obj\x86\Debug\readbmp2.Properties.Resources.resources
     文件        8031  2012-06-10 18:32  readbmp2\readbmp2\obj\x86\Debug\ResolveAssemblyReference.cache
     目录           0  2012-06-10 11:20  readbmp2\readbmp2\obj\x86\Debug\TempPE\
     文件         489  2012-06-10 11:20  readbmp2\readbmp2\Program.cs
     目录           0  2012-06-11 10:48  readbmp2\readbmp2\Properties\
     文件        1366  2012-06-10 11:20  readbmp2\readbmp2\Properties\AssemblyInfo.cs
     文件        2866  2012-06-10 11:20  readbmp2\readbmp2\Properties\Resources.Designer.cs
............此处省略5个文件信息

评论

共有 条评论