第3章 C#图像处理基础
- 格式:pdf
- 大小:1.71 MB
- 文档页数:62
,,23 照内照内照内照内照内456 1作菜1作菜 C菜C菜2作菜2作菜 C性性菜C性性菜 Win32Win32 SDK SDK然API刷然API刷然API刷、、 Windows菜Windows菜3作菜3作菜 MFC MFC MFC VCL VCL——AppWizard ——ClassWizard 4作菜作NET 4作菜作NET J2EE菜 、、C/S C/S、、B/S B/S7Managed菜Executionjava8础过v过JVM TMJVM菜=菜Java菜Virtual菜MachineJCL菜=菜Java菜Class菜Libraryx86WindowsJVMPPC Mac OS JVM ARM Palm OS JVM ……JVM JavaJCL9属类现色CLR映菜CLR映菜FxCL FxCLCLR菜=菜Common菜Language菜Runtime FxCL =菜Framework菜Class菜LibraryCommon Language Runtime.NET .NET FrameworkClass Library10属类现色XML XML、、SOAP SOAP 。
COM/DCOM COM/DCOM COM/DCOM ADO ADO 。
Web Web ADO作Net ADO作Net ADO作Net Web Web XML XML XML XSD XSD XSD。
作Net 作Net 作Net 作Net 作Net 。
。
11VC++.NetC#VJ# (FCL) (CLR)….Net Framework12.Net Framework .Net FrameworkWeb Forms Web Services XML WinFormsCLRCLSCTS13XML Web Service开放 Internet 协议 XML Web Service可编程应用程序组件 可通过标准的 Web 协议来访问UDDIUniversal Discovery Description and Integration在 Internet 上提供服务目录 XML Web Service是按照消息的格式 是按照消息的格式 和顺序来定义的 XML Web Service消费者用 消费者用XML来发送 消费者用 来发送 和接收消息 构建在开放 Internet 协议基础上WSDLWeb Services Description LanguageSOAP XML & HTTP14.NET IISWeb 表单 Server 控件 Code-BehindJSP ServletsJ2EE可运行于大多 数主要应用及 Web服务器状态: Session, .NET 数据缓存状态: 封装于 EJB 中, 也可在 Web Sessions 中CLR.NET Assembly (可使用 COM+ 服 务; 比如事务)JavaBeans EJBsJ2SE/EE JDBC (事务使 用 JTA)SQL Server Oracle DB/2, etc.SQL Server Oracle DB/2, etc.支持大多数 数据库 (通 过 Type 4 驱动程序)1516“”1718192021照内C很C很 映映MSIL MSIL 。
22作NET菜Framework 作NET菜Framework“作”System菜System菜System菜System菜System菜System菜 Object菜Object菜 作NET菜作NET菜System 、 、IO IO、、 、、23System.CollectionsSystem.DrawingSystem.Threading System.ReflectionSystem.WindowsSystem.IO System.Data菜S属类现色什 3容录24“的e骤骤o什Wo?骤釐” 3容录“ ” “ ” “Microsoft Visual Studio .NET 2005” “Microsoft Visual Studio .NET 2005” 2005C#“ ” “ ”。
“ ”“ “Visual C# ””2526 “的e骤骤o什Wo?骤釐” 3容性1.// C# HelloWorlding System;space Notepad4.{5.class HelloWorld 6.{static void Main()7.{8.Console.WriteLine("Hello World");9.}10.}11.}HelloWorld 空ain void WriteLine()System Notepad27照内什Visual Studio .NET 2005“HelloWorld ”“HelloWorld.csproj ”bin 、obj Properties。
Bin obj DebugHelloWorld.exe“ ” “ ”“HelloWorld ”“的e骤骤o什Wo?骤釐” 3容3“Hello菜World”HelloWorld.csprojAssemblyInfo.csProgram.cs28照内什 3容录“ ” C#“ ”“ ”“ : 10 ”29照内什 3容性30照内、、C#、、、、、、、、、WinformXMLWeb31照内32BitmapBitmapBitmapDataBitmapDataGraphicsGraphics3334 BitmapBitmap Bitmap GDI性GDI性GDI性。
GetPixel GetPixel SetPixel SetPixel、、Height Height WidthLockBits LockBits UnlockBits UnlockBits、、PixelFormatSystem作Drawing作Bitmap35 BitmapDataBitmapData BitmapData 。
Height Height WidthPixelFormat PixelFormatScan0Scan0Stride Stride36 GraphicsGraphics Graphics GDI性GDI性GDI性。
Graphics Graphics Graphics。
Paint Paint Paint 。
Invalidate Invalidate Invalidate37照内 31作。
。
2作。
3作CLR CLR CLR 。
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));}}Invalidate();38Rectangle 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);39double 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(rgbValu es, 0, ptr, bytes);curBitmap.UnlockBits(bmpData);Invalidate();40Rectangle 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);Invalidate();414243C#Windows Windows Windows44 描 1、“ || || ”“Visual菜C很” “Windows ” “Windows Windows”。
“ ” 。
录什45性“MenuStrip” “ ”Form1 。
。
463FormFormpublic partial class Form1 : Form{//Bitmap image;public Form1(){InitializeComponent();}47执 “ ”“ ”OpenFileDialog dlg = new OpenFileDialog();dlg.Filter = "(*.bmp;*.jpg;*.png;...)|*.bmp;*.jpg;*.png";dlg.Title = " ";if (dlg.ShowDialog() != DialogResult.OK)return;image = new Bitmap(dlg.FileName,true);Invalidate();//paint4849 —— OpenFileDialog。