| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 | using PaintDotNet.Data.SurfacePlot;using System;using System.ComponentModel;using System.Drawing;using System.Windows.Forms;namespace PaintDotNet.Instrument{    internal class SurfacePlotDialog : PdnBaseForm    {        private GroupBox groupBox1;        private GroupBox groupBox2;        private Button button1;        private PictureBox pictureBox1;        private Button button2;        private AppWorkspace appWorkspace;        private Bitmap map;        [Browsable(false)]        public AppWorkspace AppWorkspace        {            get            {                return this.appWorkspace;            }            set            {                this.appWorkspace = value;            }        }        public SurfacePlotDialog(AppWorkspace AppWorkspace)        {            //            // Required for Windows Form Designer support            //            InitializeComponent();            this.appWorkspace = AppWorkspace;            this.MaximizeBox = true;            string textFormat = PdnResources.GetString("AboutDialog.Text.Format");            this.Text = string.Format(textFormat, PdnInfo.GetBareProductName());            this.Icon = PdnInfo.AppIcon;            //this.okButton.Text = PdnResources.GetString("Form.OkButton.Text");            //this.okButton.Location = new Point((this.ClientSize.Width - this.okButton.Width) / 2, this.okButton.Top);            //this.creditsLabel.Text = PdnResources.GetString("AboutDialog.CreditsLabel.Text");            Interactive3DSurfacePlot plot = new Interactive3DSurfacePlot();            plot.run(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());        }        #region Windows Form Designer generated code        /// <summary>        /// Required method for Designer support - do not modify        /// the contents of this method with the code editor.        /// </summary>        private void InitializeComponent()        {            this.groupBox1 = new System.Windows.Forms.GroupBox();            this.pictureBox1 = new System.Windows.Forms.PictureBox();            this.groupBox2 = new System.Windows.Forms.GroupBox();            this.button1 = new System.Windows.Forms.Button();            this.button2 = new System.Windows.Forms.Button();            this.groupBox1.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();            this.groupBox2.SuspendLayout();            this.SuspendLayout();            //             // groupBox1            //             this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)            | System.Windows.Forms.AnchorStyles.Left)            | System.Windows.Forms.AnchorStyles.Right)));            this.groupBox1.Controls.Add(this.pictureBox1);            this.groupBox1.Location = new System.Drawing.Point(13, 70);            this.groupBox1.Name = "groupBox1";            this.groupBox1.Size = new System.Drawing.Size(709, 479);            this.groupBox1.TabIndex = 5;            this.groupBox1.TabStop = false;            this.groupBox1.Text = "Ô¤ÀÀ";            //             // pictureBox1            //             this.pictureBox1.Location = new System.Drawing.Point(7, 21);            this.pictureBox1.Name = "pictureBox1";            this.pictureBox1.Size = new System.Drawing.Size(696, 452);            this.pictureBox1.TabIndex = 0;            this.pictureBox1.TabStop = false;            //             // groupBox2            //             this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)            | System.Windows.Forms.AnchorStyles.Right)));            this.groupBox2.Controls.Add(this.button2);            this.groupBox2.Controls.Add(this.button1);            this.groupBox2.Location = new System.Drawing.Point(13, 12);            this.groupBox2.Name = "groupBox2";            this.groupBox2.Size = new System.Drawing.Size(709, 52);            this.groupBox2.TabIndex = 6;            this.groupBox2.TabStop = false;            this.groupBox2.Text = "²Ù×÷";            //             // button1            //             this.button1.Location = new System.Drawing.Point(628, 20);            this.button1.Name = "button1";            this.button1.Size = new System.Drawing.Size(75, 23);            this.button1.TabIndex = 0;            this.button1.Text = "button1";            this.button1.UseVisualStyleBackColor = true;            this.button1.Click += new System.EventHandler(this.button1_Click);            //             // button2            //             this.button2.Location = new System.Drawing.Point(546, 21);            this.button2.Name = "button2";            this.button2.Size = new System.Drawing.Size(75, 23);            this.button2.TabIndex = 1;            this.button2.Text = "button2";            this.button2.UseVisualStyleBackColor = true;            this.button2.Click += new System.EventHandler(this.button2_Click);            //             // SurfacePlotDialog            //             this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);            this.ClientSize = new System.Drawing.Size(734, 561);            this.Controls.Add(this.groupBox2);            this.Controls.Add(this.groupBox1);            this.Name = "SurfacePlotDialog";            this.Controls.SetChildIndex(this.groupBox1, 0);            this.Controls.SetChildIndex(this.groupBox2, 0);            this.groupBox1.ResumeLayout(false);            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();            this.groupBox2.ResumeLayout(false);            this.ResumeLayout(false);        }        private void applyButton_Click(object sender, EventArgs e)        {            Bitmap map = this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();            OpenCvSharp.Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(map);            OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat(mat.Height, mat.Width, OpenCvSharp.MatType.CV_8UC4);            OpenCvSharp.Vec4b vec = new OpenCvSharp.Vec4b(0, 255, 255, 255);            OpenCvSharp.Vec4b vec1 = new OpenCvSharp.Vec4b(0, 0, 0, 0);            for (int i = 0; i < mat.Height; i++)            {                for (int j = 0; j < mat.Width; j++)                {                    byte v = mat.At<byte>(i, j);                    if (v > 239 && v <= 255)                    {                        mat1.Set<OpenCvSharp.Vec4b>(i, j, vec);                    }                    else                    {                        mat1.Set<OpenCvSharp.Vec4b>(i, j, vec1);                    }                }            }            this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface = Surface.CopyFromBitmap(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat1));            this.Close();            /**            Bitmap map = null;            if (this.appWorkspace.ActiveDocumentWorkspace.SurfaceBox.Image == null)            {                map = new Bitmap(this.appWorkspace.ActiveDocumentWorkspace.SurfaceBox.Width, this.appWorkspace.ActiveDocumentWorkspace.SurfaceBox.Height);            }            else {                map = new Bitmap(this.appWorkspace.ActiveDocumentWorkspace.SurfaceBox.Image);            }            Graphics Grap = Graphics.FromImage(map);            Grap.DrawRectangle(new Pen(Color.Red), new Rectangle(100, 100, 20,20));            this.appWorkspace.ActiveDocumentWorkspace.SurfaceBox.Image = map;            this.Close();            **/        }        #endregion        private void RichCreditsBox_LinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e)        {            if (null != e.LinkText && e.LinkText.StartsWith("http://"))            {                PdnInfo.OpenUrl(this, e.LinkText);            }        }        private void button1_Click(object sender, EventArgs e)        {            map = new Bitmap("C:\\Users\\zyh\\Desktop\\ͼƬ\\0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg");            pictureBox1.Image = map;        }        private void button2_Click(object sender, EventArgs e)        {            Interactive3DSurfacePlot plot = new Interactive3DSurfacePlot();            plot.run(map);        }    }}
 |