打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
数字图像处理 C# 程序代码实例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging ; //需添加的头文件
using System.Linq; using System.Text;
using System.Windows.Forms;
namespace image
{ public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button3_Click(object sender, EventArgs e) %图像的灰度化
{ if (pictureBox1.Image == null) { MessageBox.Show("错误,没有导入图片!"); return; }
Bitmap bt = new Bitmap(pictureBox1.Image); Bitmap bt1 = new Bitmap(pictureBox1.Image); Color color = new Color(); for (int i = 0; i 378 || pictureBox1.Image.Width > 378) //限制导入图片过大,避免遮盖框架和按钮 { MessageBox.Show("错误,导入图片过大!应在378*378 范围内"); //可正常工作的大小 //return; this.Close(); } } // originalBt = new Bitmap(pictureBox1.Image); } private void btnOut_Click(object sender, EventArgs e) %退出 { this.Close(); } private void btnSave_Click(object sender, EventArgs e) %保存 且有多种格式任选 { //SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog2.Filter = saveFileDialog2.Filter = "Bitmap文件(*.bmp)|*.bmp|Jpeg文件(*.jpg)|*.jpg|Gif文件(*.gif)|*.gif|图像文件 (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF;*TIF"; saveFileDialog2.FilterIndex = 2; saveFileDialog2.RestoreDirectory = true; if (saveFileDialog2.ShowDialog() == DialogResult.OK) { pictureBox2.Image.Save(saveFileDialog2.FileName); } } private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) { } private void btnBinary_Click(object sender, EventArgs e) %图像的二值化 { Color ColorOrigin = new Color(); double Red, Green, Blue, Y; Bitmap Bmp1 = new Bitmap(pictureBox1.Image); int brightThreshole = 135; //? for (int i = 0; ibrightThreshole) { Color ColorProcessed = Color.FromArgb(0,0,0); Bmp1.SetPixel(i,j,ColorProcessed); } } /* pictureBox1.Refresh(); pictureBox1.Image = Bmp1;*/ pictureBox2.Refresh(); pictureBox2.Image = Bmp1; } } private void 图像缩小_Click(object sender, EventArgs e) %图像缩小 { if(pictureBox1.Image == null ) { MessageBox.Show("错误,没有导入图片!"); return; } int k = 2; Bitmap bt1 = new Bitmap(pictureBox1.Image); //需加bitmap 类型 Bitmap bt2 = new Bitmap(pictureBox1.Width / k, pictureBox1.Height / k); int Red, Green, Blue; for (int i = 0; i 255) Red = 255; if (Red <0) Red = 0; if (Green > 255) Green = 255; if (Green <0) Green = 0; if (Blue > 255) Blue = 255; if (Blue <0) Blue = 0; bt2.SetPixel(i, j, Color.FromArgb(Red, Green, Blue)); } pictureBox2.Refresh(); pictureBox2.Image = bt2; } } private void 四领域平均_Click(object sender, EventArgs e) %四邻域平均 平滑去噪 { if (pictureBox1.Image == null) { MessageBox.Show("错误,没有导入图片!"); return; } Bitmap bt1 = new Bitmap(pictureBox1.Image); Bitmap bt2 = new Bitmap(pictureBox1.Image); int R1, R2, R3, R4, Red; int G1, G2, G3, G4, Green; int B1, B2, B3, B4, Blue; for (int i = 1; i 255) R4 = 255; if (G4 > 255) G4 = 255; if (B4 > 255) B4 = 255; bt2.SetPixel(i, j, Color.FromArgb(R4, G4, B4)); } pictureBox2.Refresh(); pictureBox2.Image = bt2; } } private void btnmasico_Click(object sender, EventArgs e) % 马赛克 { if (pictureBox1.Image == null) { MessageBox.Show("错误,没有导入图片!"); return; } int degree = 10; Bitmap bt = new Bitmap(pictureBox1 .Image ); Bitmap finalbt = (Bitmap)bt.Clone(); int width = bt.Width; int height = bt.Height; BitmapData srcbtd = bt.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); BitmapData dstbtd = finalbt.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); int srcStride = srcbtd.Stride; int dstStride = dstbtd.Stride; IntPtr srcScan0 = srcbtd.Scan0; IntPtr dstScan0 = dstbtd.Scan0; unsafe //调试 生成 允许不安全代码 { byte * src =(byte *)srcScan0; byte * dst =(byte *)dstScan0; int sum =0; int square = degree*degree; byte brightness = 0; for (int i = 0; i <.image="finalbt" picturebox2="" );="" (dstbtd="" .unlockbits="" finalbt="" (srcbtd="" bt.unlockbits="" dst[k]="brightness;" +((n+j)*4));="" ((m+i)*dststride="" *)dstscan0="" {dst="(byte" ;n++)=""><3;k++) k="0;" j+="degree)">
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
C# GDI 使用操作、入门解析
C# 二维码生成和解析
用IrisSkin2.dll美化你的WinForm - 夏天的风的日志 - 网易博客
C# winfrom调用摄像头扫描二维码(完整版)
C#生成和识别二维码
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服