C#在水晶报表中加载ArcEngine地图

 

在水晶报表中加载ArcEngine地图

        众所周知

        水晶报表中动态更新

        只能通过与数据库的连接实现

 

        于是得出

        若要将地图窗口的视图动态打印出来

        可以通过以下这种思路:

        1.构建数据表,最好是在本地,避免网络耗时;在其中添加blob字段。

        2.程序中加载Crystal viewer,与报表关联;

        3.编程获取mapcontrol的当前视图,并导出为图像格式;

        4.ArcEngine导出的图片通过二进制格式读入到报表关联的数据库blob字段中;

        5.针对水晶报表中blob字段对应的对象,则可以显示出欲打印的地图。

 

        部分参考代码如下:

        private void simpleButton1_Click(object sender, System.EventArgs e)

        {

            ESRI.ArcGIS.esriSystem.IObjectCopy ObjectCopy = new ESRI.ArcGIS.esriSystem.ObjectCopyClass();

            ESRI.ArcGIS.Carto.IActiveView View0;

            View0 = this.axMapControl1.ActiveView;

            //导出图片

            ESRI.ArcGIS.Output.IExport Export;

            Export = new ESRI.ArcGIS.Output.ExportJPEGClass();

            Export.ExportFileName = "1053.jpg";

            //Export.Resolution = 96;

 

            ESRI.ArcGIS.Display.tagRECT exportRec;

            exportRec = View0.ExportFrame;

            ESRI.ArcGIS.Geometry.IEnvelope Bounds = new ESRI.ArcGIS.Geometry.EnvelopeClass();

            Bounds.PutCoords(exportRec.left, exportRec.top, exportRec.right, exportRec.bottom);

            Export.PixelBounds = Bounds;

 

            int hdc;

            hdc = Export.StartExporting();

 

            View0.Output(hdc, 96, ref exportRec, null, null);

 

            Export.FinishExporting();

            Export.Cleanup();

 

            Form2 frm = new Form2();

            frm.ShowDialog();

        }

 

 

 

 

 

 

        private void Form2_Load(object sender, System.EventArgs e)

        {

            YSSQ cr = new YSSQ();

            DataSet ds = new DataSet();

            String path;

            DataColumn column = new DataColumn();

            DataRow row;

 

            //调整格式

            BlobFieldObject BObj;

            BObj = cr.ReportDefinition.ReportObjects["XMTB1"] as BlobFieldObject;

 

 

            //构造一个对应于xsd文件的表结构

            ds.Tables.Add("Map");

            ds.Tables[0].Columns.Add("XMBH", System.Type.GetType("System.String"));

            ds.Tables[0].Columns.Add("XMTB", System.Type.GetType("System.Byte[]"));

            //写入数据

            path = "1053.jpg";

 

            row = ds.Tables[0].NewRow();

            row[0] = "J0000001";

            FileStream fs = new FileStream(path, FileMode.Open);//获取文件流

            BinaryReader br = new BinaryReader(fs);//创建二进制读取对象

            int len = (int)br.BaseStream.Length;

            row[1] = br.ReadBytes(len);

            ds.Tables[0].Rows.Add(row);

            br.Close();

            fs.Close();

 

            cr.SetDataSource(ds);

            this.crystalReportViewer1.ReportSource = cr;

 

 

        }

来自:http://www.cnblogs.com/columbus2/archive/2007/08/02/840325.html

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页