《数字图像处理的代码》由会员分享,可在线阅读,更多相关《数字图像处理的代码(8页珍藏版)》请在金锄头文库上搜索。
1、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;namespace final public partial class Form1 : Form public Form1() InitializeComponent(); Bitmap recBitmap; private void openT
2、oolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog openFileDlg = new OpenFileDialog(); openFileDlg.ShowDialog(); String fileName = openFileDlg.FileName; recBitmap = new Bitmap(fileName); recPicBox.Image = recBitmap; private void rToolStripMenuItem_Click(object sender, EventArgs e) int
3、 width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitmap = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j height; j+) Color c = recBitmap.GetPixel(i, j); int r = c.R; Color cc = Color.FromArgb(r, 0, 0); decBitmap.SetPixel(i, j, cc); decPicBox.Image = decBi
4、tmap; private void gToolStripMenuItem_Click(object sender, EventArgs e) int width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitmap = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j height; j+) Color c = recBitmap.GetPixel(i, j); int g = c.G; Color cc = Col
5、or.FromArgb(0, g, 0); decBitmap.SetPixel(i, j, cc); decPicBox.Image = decBitmap; private void bToolStripMenuItem_Click(object sender, EventArgs e) int width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitmap = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j
6、height; j+) Color c = recBitmap.GetPixel(i, j); int b = c.B; Color cc = Color.FromArgb(0, 0, b); decBitmap.SetPixel(i, j, cc); decPicBox.Image = decBitmap; private void grayToolStripMenuItem_Click(object sender, EventArgs e) int width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitma
7、p = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j height; j+) Color c = recBitmap.GetPixel(i, j); int r = c.R; int g = c.G; int b = c.B; int gray = (r + g + b) / 3; Color cc = Color.FromArgb(gray, gray, gray); decBitmap.SetPixel(i, j, cc); decPicBox.Image = decBitmap; pri
8、vate void vToolStripMenuItem_Click(object sender, EventArgs e) int width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitmap = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j height; j+) Color c = recBitmap.GetPixel(i, j); decBitmap.SetPixel(width - i - 1, j,
9、 c); decPicBox.Image = decBitmap; private void gToolStripMenuItem1_Click(object sender, EventArgs e) int width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitmap = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j height; j+) Color c = recBitmap.GetPixel(i, j)
10、; decBitmap.SetPixel(i, height - j - 1, c); decPicBox.Image = decBitmap; private void vtToolStripMenuItem_Click(object sender, EventArgs e) int width = recBitmap.Width; int height = recBitmap.Height; Bitmap decBitmap = new Bitmap(width, height); for (int i = 0; i width; i+) for (int j = 0; j height; j+) Color c = recBitmap.GetPixel(i, j); int vtran = i - width / 3; if (vtran 0) vtran = 0; decBitmap.SetPixel(vtran, j, c);