您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 基于c#的图像处理源代码
  所属分类: C#
  开发工具:
  文件大小: 982kb
  下载次数: 0
  上传时间: 2010-12-11
  提 供 者: zhan*****
 详细说明: 基于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: break; } } } private void close_Click(object sender, EventArgs e) { this.Close(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; if(curBitmap != null) { g.DrawImage(curBitmap, 160, 20, curBitmap.Width, curBitmap.Height); } } private void pixel_Click(object sender, EventArgs e) { if(curBitmap != null) { myTimer.ClearTimer(); myTimer.Start(); Color curColor; int ret; for (int i = 0; i < curBitmap.Width; i++) { for (int j = 0; j < curBitmap.Height ; j++) { curColor = curBitmap.GetPixel(i,j); ret = (int)(curColor.R * 0.299 + curColor.G * 0.587 + curColor.B * 0.114); curBitmap.SetPixel(i, j, Color.FromArgb(ret, ret, ret)); } } myTimer.Stop(); timeBox.Text = myTimer.Duration.ToString("####.##") + " 毫秒"; Invalidate(); } } private void memory_Click(object sender, EventArgs e) { if (curBitmap != null) { myTimer.ClearTimer(); myTimer.Start(); Rectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height); System.Drawing.Imaging.BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, curBitmap.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = curBitmap.Width * curBitmap.Height * 3; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); double colorTemp = 0; for (int i = 0; i < rgbValues.Length; i += 3) { colorTemp = rgbValues[i + 2] * 0.299 + rgbValues[i + 1] * 0.587 + rgbValues[i] * 0.114; rgbValues[i] = rgbValues[i + 1] = rgbValues[i + 2] = (byte)colorTemp; } System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); curBitmap.UnlockBits(bmpData); myTimer.Stop(); timeBox.Text = myTimer.Duration.ToString("####.##") + " 毫秒"; Invalidate(); } } private void pointer_Click(object sender, EventArgs e) { if (curBitmap != null) { myTimer.ClearTimer(); myTimer.Start(); Rectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height); System.Drawing.Imaging.BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, curBitmap.PixelFormat); byte temp = 0; unsafe { byte* ptr = (byte*)(bmpData.Scan0); for (int i = 0; i < bmpData.Height; i++) { for (int j = 0; j < bmpData.Width; j++) { temp = (byte)(0.299 * ptr[2] + 0.587 * ptr[1] + 0.114 * ptr[0]); ptr[0] = ptr[1] = ptr[2] = temp; ptr += 3; } ptr += bmpData.Stride - bmpData.Width * 3; } } curBitmap.UnlockBits(bmpData); myTimer.Stop(); timeBox.Text = myTimer.Duration.ToString("####.##") + " 毫秒"; Invalidate(); } } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: c# 图像处理 源代码
 输入关键字,在本站1000多万海量源码库中尽情搜索: