The procedure is as follows;
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using Emgu.CV;using Emgu.cv.cvenum;using emgu.cv.structure;using system.xml;using system.xml.serialization;using System.IO;namespace windowsformsapplication1{public partial class Form1:form {public Form1 () {Initializeco Mponent (); }///<summary>///show blue///</summary>//<param name= "Sender" ></param >//<param name= "E" ></param> private void Button1_Click (object sender, EventArgs e) {IMAGE<BGR, byte> img1 = new IMAGE<BGR, byte> (new Bgr (255, 0, 0)); pictureBox1.Image = Img1. Tobitmap (); }///<summary>///Open a picture from the dialog box;///</summary>//<param name= "SenDer "></param>//<param name=" E "></param> private void button2_click (object sender, Ev Entargs e) {string strFileName = string. Empty; OpenFileDialog ofd = new OpenFileDialog (); if (OFD. ShowDialog () ==dialogresult.ok) {image<bgr, byte> img1 = new IMAGE<BGR, byte> (OFD. FileName); pictureBox1.Image = Img1. Tobitmap (); }}///<summary>//for pixel operation;///</summary>//<param name= "Sender" & gt;</param>//<param name= "E" ></param> private void Button3_Click (object sender, Eventar GS e) {image<bgr, byte> img1 = new IMAGE<BGR, byte> (New Bgr (250, 0, 0)); Byte B1 = 255; BGR yellow = new Bgr (0, 255, 255);//The RGB value can be interpreted as a vector overlay;//first for (int i=20;i<60;i++) { for (int j=20;j<60;j++) {img1. Data[i, j, 0] = 0; Img1. Data[i, j, 1] = B1; Img1. Data[i, J, 2] = B1; }}//second for (int i=120;i<160;i++) {for (int j=20;j<60 ; j + +) {img1[i, j] = yellow; }}//third byte[,,] data = img1. Data; delivery address only; for (int i=20;i<60;i++) {for (int j=120;j<160;j++) { Data[i, j, 0] = 0; Data[i, j, 1] = B1; Data[i, J, 2] = B1; }} picturebox1.image = Img1. Tobitmap (); }///<summary>///image overlay;///</summary>//<param name= "Sender" ></param >//<param name= "E" ></param> private void Button4_Click (object sender, EventarGS e) {image<bgr, byte> imgblue = new IMAGE<BGR, byte> (new Bgr (255, 0, 0)); IMAGE<BGR, byte> imggreen = new IMAGE<BGR, byte> (new Bgr (0, 255, 0)); IMAGE<BGR, byte> imgred = new IMAGE<BGR, byte> (new Bgr (0, 0, 255)); IMAGE<BGR, byte> img1 = imgblue + Imggreen + imgred; pictureBox1.Image = Img1. Tobitmap (); }///<summary>//change each pixel point;///</summary>//<param name= "Sender" >< /param>//<param name= "E" ></param> private void Button5_click (object sender, EventArgs e) {//you need choose a gray picture Image<gray, byte> imggray = new Image<gray, BYTE&G t; ("E:\\testpictures\\rice.png"); Single is one-precision floating-point number Image<gray, single> img1 = imggray.convert<single> (Delegate (Byte b) { Return (single) Math.sin (b * b/255.0); } ); pictureBox1.Image = Img1. Tobitmap (); Img1. Dispose ();//If you do not add this, the system will automatically log off the picture, but try to manually log out;}//<summary>//image to XML//</summary >//<param name= "sender" ></param>//<param name= "E" ></param> private V OID Button6_click (object sender, EventArgs e) {string strFileName = string. Empty; OpenFileDialog ofd = new OpenFileDialog (); if (OFD. ShowDialog () ==dialogresult.ok) {image<bgr, byte> img1 = new IMAGE<BGR, byte> (OFD. FileName); pictureBox1.Image = Img1. Tobitmap (); Note References Systom.xml and IO, etc. StringBuilder SB1 = new StringBuilder (); (New XmlSerializer (typeof (IMAGE<BGR, byte>)). Serialize (New StringWriter (SB1), IMG1); XmlDocument XMLDoc = new XmlDocument (); Xmldoc.loadxml (SB1. ToString ()); Xmldoc.save ("Image.xml"); }}////<summary>//XML to image, need to load XML file, I use the last button generated XML file;///</summary> <param name= "Sender" ></param>///<param name= "E" ></param> private void button 7_click (object sender, EventArgs e) {string strFileName = string. Empty; OpenFileDialog ofd = new OpenFileDialog (); if (OFD. ShowDialog () = = DialogResult.OK) {XmlDocument doc = new XmlDocument (); Doc. Load (OFD. FileName); IMAGE<BGR, byte> img1 = (IMAGE<BGR, byte>) (New XmlSerializer (typeof (IMAGE<BGR, byte> ))). Deserialize (new XmlNodeReader (DOC)); pictureBox1.Image = Img1. Tobitmap (); } } }}
Operation Result:
The second program finishes.
C # + WinForm + EMGUCV Learn II: Create and manipulate pictures