Esempio n. 1
0
 /// <summary>
 /// Form_Load事件中实现画图
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form2_Load(object sender, EventArgs e)
 {
     this.Width            = 360;
     pictureBox2.Dock      = DockStyle.Fill;
     pictureBox2.BackColor = Color.White;
     pictureBox2.Paint    += new System.Windows.Forms.PaintEventHandler(this.pictureBox2_Paint);
     this.Controls.Add(pictureBox2);
     if (flag == 1)
     {
         GetWinByName gwbn = new GetWinByName();
         WinN = gwbn.GetWinN(Form1.abl.Wins, Windowname);
         map  = new Bitmap(Form1.abl.Wins[WinN].pictureBox1.Width, Form1.abl.Wins[WinN].pictureBox1.Height);
     }
 }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            /// <summary>
            /// No Display 时创建imageview新实例
            /// <summary>
            if (comboBox1.Text == "No Display")
            {
                /// <summary>
                /// comboBox操作,类似envi
                /// <summary>
                //windowsnum++;
                comboBox1.Items.Add("Display #" + 1);
                comboBox1.SelectedItem = "Display #" + 1;
                comboBox1.Items.Remove("No Display");
                /// <summary>
                /// 定义新窗体
                /// <summary>
                imageview imv = new imageview("Display #" + 1);
                imv.Text = "Display #" + 1;
                /// <summary>
                /// 选择灰度(单波段)显示
                /// <summary>
                if (radioButton1.Checked)
                {
                    if (textBox1.Text != "")
                    {
                        /// <summary>
                        ///索引数据流,得到数据
                        /// <summary>
                        string pathmark = Path.GetFileName(textBox1.Text);

                        GetDataByFilename gdb = new GetDataByFilename();
                        int           i       = gdb.getnumber(readmore, pathmark);
                        GetBandByname gbn     = new GetBandByname();
                        int           single  = gbn.getnumber(readmore[i].Bandsname, this.textBox1.Text.Substring(0, this.textBox1.Text.IndexOf(pathmark) - 1)
                                                              , readmore[i].bands);
                        /// <summary>
                        /// imv实例中各项数据初始化
                        /// <summary>
                        imv.ColumnCounts = readmore[i].ColumnCounts;
                        imv.LineCounts   = readmore[i].LineCounts;
                        imv.bands        = 1;
                        imv.showdata     = new int[imv.bands, imv.ColumnCounts *imv.LineCounts];
                        imv.BandsDataD   = new double[imv.bands, imv.ColumnCounts *imv.LineCounts];
                        imv.bandstemp    = new int[imv.bands, imv.ColumnCounts *imv.LineCounts];
                        /// <summary>
                        ///原数据存储
                        /// <summary>
                        for (int j = 0; j < readmore[i].ColumnCounts * readmore[i].LineCounts; j++)
                        {
                            imv.BandsDataD[0, j] = readmore[i].BandsDataD[single, j];
                        }

                        imv.pictureBox1.Height = imv.LineCounts;
                        imv.pictureBox1.Width  = imv.ColumnCounts;

                        ///窗口状态初始化
                        imv.handleBopen();
                        /// <summary>
                        ///通过LinearShow方法,将原数据拉伸至0-255用于显示
                        /// <summary>
                        imagestretch images = new imagestretch(imv.ColumnCounts, imv.LineCounts, imv.bands);
                        //images.LinearShow(imv.showdata, imv.BandsDataD);
                        imv.showdata = images.TwoPercentStretch(imv.BandsDataD);
                        /// <summary>
                        ///窗口命名
                        /// <summary>
                        imv.Text = textBox1.Text;
                        /// <summary>
                        ///显示图像
                        /// <summary>
                        ImageShow ims = new ImageShow();
                        imv.pictureBox1.Refresh();
                        Bitmap map = new Bitmap(imv.pictureBox1.Width, imv.pictureBox1.Height);

                        ims.showimage(imv.showdata, imv.ColumnCounts, imv.LineCounts, imv.bands, map);

                        imv.pictureBox1.Image = map;

                        imv.Show();
                        imv.Visible = true;
                    }
                    else
                    {
                        MessageBox.Show("请选择波段!");
                    }
                }
                else if (radioButton2.Checked)
                {
                    if (textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "")
                    {
                        /// <summary>
                        ///从list数据流中按文件名索引数据。
                        /// <summary>
                        string            pathmark2 = Path.GetFileName(textBox2.Text);
                        string            pathmark3 = Path.GetFileName(textBox3.Text);
                        string            pathmark4 = Path.GetFileName(textBox4.Text);
                        GetDataByFilename gdb       = new GetDataByFilename();
                        int i2 = gdb.getnumber(readmore, pathmark2);
                        int i3 = gdb.getnumber(readmore, pathmark3);
                        int i4 = gdb.getnumber(readmore, pathmark4);
                        /// <summary>
                        /// 按波段名索引波段号
                        /// <summary>
                        GetBandByname gbn   = new GetBandByname();
                        int           Rband = gbn.getnumber(readmore[i2].Bandsname, this.textBox2.Text.Substring(0, this.textBox2.Text.IndexOf(pathmark2) - 1)
                                                            , readmore[i2].bands);
                        int Gband = gbn.getnumber(readmore[i3].Bandsname, this.textBox3.Text.Substring(0, this.textBox3.Text.IndexOf(pathmark3) - 1)
                                                  , readmore[i3].bands);
                        int Bband = gbn.getnumber(readmore[i4].Bandsname, this.textBox4.Text.Substring(0, this.textBox4.Text.IndexOf(pathmark4) - 1)
                                                  , readmore[i4].bands);
                        if (Form1.boduan[i2].ColumnCounts == Form1.boduan[i3].ColumnCounts &&
                            Form1.boduan[i2].ColumnCounts == Form1.boduan[i4].ColumnCounts &&
                            Form1.boduan[i2].LineCounts == Form1.boduan[i3].LineCounts &&
                            Form1.boduan[i2].LineCounts == Form1.boduan[i4].LineCounts)
                        {
                            /// <summary>
                            /// imv实例中各项数据初始化
                            /// <summary>
                            imv.LineCounts   = readmore[i2].LineCounts;
                            imv.ColumnCounts = readmore[i3].ColumnCounts;
                            imv.bands        = 3;
                            imv.showdata     = new int[imv.bands, imv.LineCounts *imv.ColumnCounts];
                            imv.BandsDataD   = new double[imv.bands, imv.ColumnCounts *imv.LineCounts];
                            /// <summary>
                            ///任意图像任意波段合成(数据传递)
                            /// <summary>
                            for (int j = 0; j < imv.ColumnCounts * imv.LineCounts; j++)
                            {
                                imv.BandsDataD[0, j] = readmore[i2].BandsDataD[Rband, j];
                            }

                            for (int j = 0; j < imv.ColumnCounts * imv.LineCounts; j++)
                            {
                                imv.BandsDataD[1, j] = readmore[i3].BandsDataD[Gband, j];
                            }

                            for (int j = 0; j < imv.ColumnCounts * imv.LineCounts; j++)
                            {
                                imv.BandsDataD[2, j] = readmore[i4].BandsDataD[Bband, j];
                            }

                            imv.pictureBox1.Height = imv.LineCounts;
                            imv.pictureBox1.Width  = imv.ColumnCounts;
                            ///窗口状态初始化
                            imv.handleBopen();
                            /// <summary>
                            ///通过LinearShow方法,将原数据拉伸至0-255用于显示
                            /// <summary>
                            imagestretch images = new imagestretch(imv.ColumnCounts, imv.LineCounts, imv.bands);
                            images.LinearShow(imv.showdata, imv.BandsDataD);
                            //imv.showdata = images.TwoPercentStretch(imv.BandsDataD);

                            /// <summary>
                            ///窗口命名
                            /// <summary>
                            imv.Text = textBox2.Text + "&" + textBox3.Text + "&" + textBox4.Text;
                            /// <summary>
                            ///显示图像
                            /// <summary>
                            imv.pictureBox1.Refresh();
                            ImageShow ims = new ImageShow();
                            Bitmap    map = new Bitmap(imv.pictureBox1.Width, imv.pictureBox1.Height);
                            ims.showimage(imv.showdata, imv.ColumnCounts, imv.LineCounts, imv.bands, map);


                            imv.pictureBox1.Image = map;

                            imv.Show();
                            imv.Visible = true;
                        }
                        else
                        {
                            MessageBox.Show("波段规格不匹配!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("请输入波段!");
                    }
                }
                /// <summary>
                /// imv实例加入Wins泛型中
                /// <summary>
                Wins.Add(imv);
            }
            /// <summary>
            ///对已存在的imageview窗体进行数据传递和操作
            /// <summary>
            else
            {
                /// <summary>
                /// 搜索窗口
                /// <summary>
                GetWinByName gwn    = new GetWinByName();
                int          WinNbr = gwn.GetWinN(Wins, comboBox1.Text);

                if (radioButton1.Checked)
                {
                    if (textBox1.Text != "")
                    {
                        string pathmark = Path.GetFileName(textBox1.Text);
                        /// <summary>
                        ///索引数据流,得到数据
                        /// <summary>
                        GetDataByFilename gdb = new GetDataByFilename();
                        int           i       = gdb.getnumber(readmore, pathmark);
                        GetBandByname gbn     = new GetBandByname();
                        int           single  = gbn.getnumber(readmore[i].Bandsname, this.textBox1.Text.Substring(0, this.textBox1.Text.IndexOf(pathmark) - 1)
                                                              , readmore[i].bands);
                        /// <summary>
                        /// imv实例中各项数据初始化
                        /// <summary>
                        Wins[WinNbr].ColumnCounts = readmore[i].ColumnCounts;
                        Wins[WinNbr].LineCounts   = readmore[i].LineCounts;
                        Wins[WinNbr].bands        = 1;
                        Wins[WinNbr].showdata     = new int[Wins[WinNbr].bands, Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts];
                        Wins[WinNbr].BandsDataD   = new double[Wins[WinNbr].bands, Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts];
                        /// <summary>
                        ///原数据存储
                        /// <summary>
                        for (int j = 0; j < readmore[i].ColumnCounts * readmore[i].LineCounts; j++)
                        {
                            Wins[WinNbr].BandsDataD[0, j] = readmore[i].BandsDataD[single, j];
                        }

                        Wins[WinNbr].pictureBox1.Height = Wins[WinNbr].LineCounts;
                        Wins[WinNbr].pictureBox1.Width  = Wins[WinNbr].ColumnCounts;

                        ///窗口状态初始化
                        Wins[WinNbr].handleBopen();
                        /// <summary>
                        ///通过LinearShow方法,将原数据拉伸至0-255用于显示
                        /// <summary>
                        imagestretch images = new imagestretch(Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands);
                        //images.LinearShow(Wins[WinNbr].showdata, Wins[WinNbr].BandsDataD);
                        Wins[WinNbr].showdata = images.TwoPercentStretch(Wins[WinNbr].BandsDataD);
                        /// <summary>
                        /// 图像拉伸数据初始化和赋值
                        /// <summary>
                        BandpixelInitialize bpi = new BandpixelInitialize();
                        bpi.Initialization(out Wins[WinNbr].bandstemp, Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts
                                           , Wins[WinNbr].LineCounts, Wins[WinNbr].bands);
                        /// <summary>
                        ///窗口命名
                        /// <summary>
                        Wins[WinNbr].Text = textBox1.Text;
                        /// <summary>
                        ///显示图像
                        /// <summary>
                        ImageShow ims = new ImageShow();
                        //ims.showimage(bandints,ColumnCounts,LineCounts)
                        Wins[WinNbr].pictureBox1.Refresh();
                        Bitmap map = new Bitmap(Wins[WinNbr].pictureBox1.Width, Wins[WinNbr].pictureBox1.Height);

                        ims.showimage(Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands, map);

                        Wins[WinNbr].pictureBox1.Image = map;

                        Wins[WinNbr].Show();
                        Wins[WinNbr].Visible = true;
                    }
                    else
                    {
                        MessageBox.Show("请输入波段!");
                    }
                }
                else if (radioButton2.Checked)
                {
                    if (textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "")
                    {
                        /// <summary>
                        ///从list数据流中按文件名索引数据。
                        /// <summary>
                        string            pathmark2 = Path.GetFileName(textBox2.Text);
                        string            pathmark3 = Path.GetFileName(textBox3.Text);
                        string            pathmark4 = Path.GetFileName(textBox4.Text);
                        GetDataByFilename gdb       = new GetDataByFilename();
                        int i2 = gdb.getnumber(readmore, pathmark2);
                        int i3 = gdb.getnumber(readmore, pathmark3);
                        int i4 = gdb.getnumber(readmore, pathmark4);
                        /// <summary>
                        /// 按波段名索引波段号
                        /// <summary>
                        GetBandByname gbn   = new GetBandByname();
                        int           Rband = gbn.getnumber(readmore[i2].Bandsname, this.textBox2.Text.Substring(0, this.textBox2.Text.IndexOf(pathmark2) - 1)
                                                            , readmore[i2].bands);
                        int Gband = gbn.getnumber(readmore[i3].Bandsname, this.textBox3.Text.Substring(0, this.textBox3.Text.IndexOf(pathmark3) - 1)
                                                  , readmore[i3].bands);
                        int Bband = gbn.getnumber(readmore[i4].Bandsname, this.textBox4.Text.Substring(0, this.textBox4.Text.IndexOf(pathmark4) - 1)
                                                  , readmore[i4].bands);
                        if (Form1.boduan[i2].ColumnCounts == Form1.boduan[i3].ColumnCounts &&
                            Form1.boduan[i2].ColumnCounts == Form1.boduan[i4].ColumnCounts &&
                            Form1.boduan[i2].LineCounts == Form1.boduan[i3].LineCounts &&
                            Form1.boduan[i2].LineCounts == Form1.boduan[i4].LineCounts)
                        {
                            /// <summary>
                            /// imv实例中各项数据初始化
                            /// <summary>
                            Wins[WinNbr].LineCounts   = readmore[i2].LineCounts;
                            Wins[WinNbr].ColumnCounts = readmore[i3].ColumnCounts;
                            Wins[WinNbr].bands        = 3;
                            Wins[WinNbr].showdata     = new int[3, Wins[WinNbr].LineCounts * Wins[WinNbr].ColumnCounts];
                            Wins[WinNbr].BandsDataD   = new double[3, Wins[WinNbr].LineCounts * Wins[WinNbr].ColumnCounts];
                            /// <summary>
                            ///任意图像任意波段合成(数据传递)
                            /// <summary>
                            for (int j = 0; j < Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts; j++)
                            {
                                Wins[WinNbr].BandsDataD[0, j] = readmore[i2].BandsDataD[Rband, j];
                            }

                            for (int j = 0; j < Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts; j++)
                            {
                                Wins[WinNbr].BandsDataD[1, j] = readmore[i3].BandsDataD[Gband, j];
                            }

                            for (int j = 0; j < Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts; j++)
                            {
                                Wins[WinNbr].BandsDataD[2, j] = readmore[i4].BandsDataD[Bband, j];
                            }

                            Wins[WinNbr].pictureBox1.Height = Wins[WinNbr].LineCounts;
                            Wins[WinNbr].pictureBox1.Width  = Wins[WinNbr].ColumnCounts;
                            ///窗口状态初始化
                            Wins[WinNbr].handleBopen();
                            /// <summary>
                            ///通过LinearShow方法,将原数据拉伸至0-255用于显示
                            /// <summary>
                            imagestretch images = new imagestretch(Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands);
                            //images.LinearShow(Wins[WinNbr].showdata, Wins[WinNbr].BandsDataD);
                            Wins[WinNbr].showdata = images.TwoPercentStretch(Wins[WinNbr].BandsDataD);
                            /// <summary>
                            /// 图像拉伸数据初始化和赋值
                            /// <summary>
                            BandpixelInitialize bpi = new BandpixelInitialize();
                            bpi.Initialization(out Wins[WinNbr].bandstemp, Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts
                                               , Wins[WinNbr].LineCounts, Wins[WinNbr].bands);
                            /// <summary>
                            ///窗口命名
                            /// <summary>
                            Wins[WinNbr].Text = textBox2.Text + "&" + textBox3.Text + "&" + textBox4.Text;
                            /// <summary>
                            ///显示图像
                            /// <summary>
                            Wins[WinNbr].pictureBox1.Refresh();
                            ImageShow ims = new ImageShow();
                            Bitmap    map = new Bitmap(Wins[WinNbr].pictureBox1.Width, Wins[WinNbr].pictureBox1.Height);
                            ims.showimage(Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands, map);


                            Wins[WinNbr].pictureBox1.Image = map;

                            Wins[WinNbr].Show();
                            Wins[WinNbr].Visible = true;
                        }
                        else
                        {
                            MessageBox.Show("波段规格不匹配!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("请输入波段!");
                    }
                }
            }
        }