软件GIS系统采用了mapx5.0控件,现在利用mapx控件自己带的保存图片的方法,代码如下:
        public void SaveTheMap(string SavePath, string Format, int Width, int Height)
        {
            this._Map.PaperUnit = PaperUnitConstants.miPaperUnitCentimeter;
            this._Map.ExportMap("CLIPBOARD", MapXLib.ExportFormatConstants.miFormatBMP, Width, Height);
            //运行完上面一句话就直接跳到下面粘的第二段代码中
            Image im = System.Windows.Forms.Clipboard.GetImage();
            if (Format == "JPG")
                im.Save(SavePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            else if (Format == "BMP")
                im.Save(SavePath, System.Drawing.Imaging.ImageFormat.Bmp);
            System.Windows.Forms.Clipboard.Clear();
        }
下面是第二段代码,这段代码是主窗体的Designer.cs 里面的
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
很奇怪软件也不报错,运行完那句之后直接就去dispose 了,不知道为什么,大家有没有碰到类似的情况 ,求大虾指点~~

解决方案 »

  1.   

    ExportMap里面干了什么,是否执行了Close
      

  2.   

    是map控件自己的方法:
    public virtual void ExportMap(string destination, ExportFormatConstants format, object width, object height);
    看不到里面的代码,但是我上面粘出来的第一段代码,我在其它的地方也有用到,运行时就直接到下一句话了
      

  3.   

    问了几个同事,说是可能你VS2010装的有问题。他们说有时不显示错误,直接进入dispose , 他们也不知道为什么,现在这个软件要的紧,这周就得做完,重装的话太麻烦了 
      

  4.   

    感觉ExportMap方法可能执行失败了,如果成功应该会继续执行的
      

  5.   

    我列一下这个函数在其它地方的调用:先是进入下面这个    
        public void createTempPic()
            {
                //保存图例
                string FolderPath = Application.StartupPath + "\\Pictures\\";
                saveLengend(Thresholds._VoltRangeString, Thresholds._VoltColors, "volt");
                saveLengend(Thresholds._BERRangeString, Thresholds._BERColors, "ber");
                saveLengend(Thresholds._MERRangeString, Thresholds._MERColors, "mer");
                saveLengend(Thresholds._LDPCRangeString, Thresholds._LDPCColors, "ldpc");
                saveLengend(Thresholds._SNRRangeString, Thresholds._SNRColors, "snr");
                saveLengend(Thresholds._RSRangeString, Thresholds._RSBLERColors, "rs");
                ////保存路测图
                this.selectedSection.Map.Map.Layers._Item("StrLayer").Visible = true;
                this.selectedSection.Map.Map.Layers._Item("SnrLayer").Visible = false;
                this.selectedSection.Map.Map.Layers._Item("BerLayer").Visible = false;
                this.selectedSection.Map.Map.Layers._Item("MerLayer").Visible = false;
                this.selectedSection.Map.Map.Layers._Item("RsLayer").Visible = false;
                this.selectedSection.Map.Map.Layers._Item("LdpcLayer").Visible = false;
                savePic("StrCover", "volt");然后再进入下面这个:
            public void savePic(string picName, string type)
            {
                string Format;
                Format = "JPG";
                string s = Application.StartupPath + "\\Pictures\\" + picName + "." + Format;
                int w, h;
                if (selectedSection.Map.Map.Width > selectedSection.Map.Map.Height)
                {
                    w = 65;
                    h = 70 * selectedSection.Map.Map.Height / selectedSection.Map.Map.Width;
                }
                else
                {                h = 65;
                    w = 70 * selectedSection.Map.Map.Width / selectedSection.Map.Map.Height;            }
    //就是下面这句
                selectedSection.Map.SaveTheMap(s, Format, w, h);
                System.Drawing.Bitmap bmp = new Bitmap(s);
                System.Drawing.Image volt;
                Graphics g = Graphics.FromImage(bmp);
                volt = new Bitmap(Application.StartupPath + "\\Pictures\\" + type + ".bmp");
                g.DrawImage(volt, 0, 0);            bmp.Save(Application.StartupPath + "\\Pictures\\" + type + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                volt.Dispose();
                bmp.Dispose();
                g.Dispose();
                File.Delete(s);
            }
      

  6.   

    不好意思啊大家,问题解决了,this._Map.PaperUnit = PaperUnitConstants.miPaperUnitCentimeter;用的分米单位,我传进的参数太大了,导致图片不能正确地在剪切板上显示出来,所以窗体去DISPOSE了,大家接分吧