资源简介
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个文件信息
相关资源
- C#中通用TCP/IP客户/服务器通信库源代
- C# 贪吃蛇demo最简单的代码
- C#串口MudbusRTU协议编程
- C# 简单绘图程序
- C#远程屏幕监控含源码
- c#记事本源码新建、保存、另存为、打
- c#编程规范
- C#.net中树型目录编写的点菜系统
- C#_winform操作excel(打开、内嵌)
- vs2010 C# 计算器仿 Windows 自带的计算器
- C# .net守护程序(重启CPU占用率检测)
- 北大青鸟S1第一学期第三本书C#和SQL数
- 一个简单的AD转换程序
- C# winform 三层架构设计登陆小模块演示
- C# 网页抓取网络爬虫的新闻弹窗小工
- C#物体抛物线移动,适用于投掷物体轨
- c#题库试题资源很齐全
- 是男人就下100层(C#版)源码
- C# WEB投票
- winform高效率的分页查询
- C# 方法大全真的是挺全的了
- C#与mysql交互
- HZK16汉字点阵(c#)
- 用c# 写的上位机程序
- c# ae 测量点、线、面并计算长度、周
- C# 后台动态增加chart图表
- C# 通过委托和线程实现chart控件的实时
- RosAPI C#
- C#窗体程序对数据库的增删改查操作三
- Innosetup C# 打包代码 完美版
评论
共有 条评论