阅读:3241回复:5
请教AO导出地图为JPG的问题(加问导出为SVG等矢量格式的方法)
<P>我在使用C#+AO 开发的过程中,将一个从SDE中读取的featureclass实例导出成JPG图像时,出了问题。错误提示必须产生一个ArcMap的MxDocument实例,通过它的IActiveview接口获取Envelope,然后才能输出一个Jpg图像。</P>
<P>请教各位大虾,有没有什么办法可以在软件逻辑中生成一个类似ARCMAP的地图容器,而不用MAP控件显示地图出来的办法呢?</P> <P>———————————————————————————————————————</P> <P>我还想问问怎么导出为PDF、SVG等矢量格式呀?请问各位大虾有范例可以参考吗?</P> [此贴子已经被作者于2005-8-8 17:00:17编辑过]
|
|
1楼#
发布于:2005-08-08 14:49
<P>没办法生成,arcmap就是arcmap</P>
<P>但是你使用mapcontrol或者picture等显示地图,都可以自己定义iactiveview和imap,获取你需要的envelop</P> <P>下面是vba程序,你只需要把arcmap的定义,改到你目前的环境中</P> <P>Public Sub ExportActiveView()<BR> Dim pMxDoc As IMxDocument<BR> Set pMxDoc = ThisDocument<BR> Dim pActiveView As IActiveView<BR> Set pActiveView = pMxDoc.ActiveView<BR> <BR> 'Create an ExportJPEG object and QI the pExport interface pointer onto it.<BR> ' To export to a format other than JPEG, simply create a different CoClass here<BR> ' and change the file extension of the ExportFileName.<BR> Dim pExport As IExport<BR> Set pExport = New ExportJPEG<BR> pExport.ExportFileName = "C:\ExportTest1.jpg"</P> <P> <BR> 'Set the export object resolution to 96 dpi. The default screen resolution for<BR> ' MS Windows is usually 96dpi, and this value is also the default resolution for all<BR> ' of the ArcGIS image format exporters. The vector format exporters (PDF, AI, etc.)<BR> ' default to 300 dpi, so we should explicitly set resolution here to be certain we<BR> ' are working with a resolution of 96.<BR> pExport.Resolution = 96<BR> <BR> 'For both PageLayout and Map objects, the ExportFrame property always holds a tagRECT<BR> ' structure appropriate for exporting. The values in the tagRECT correspond to the width<BR> ' and height to export, measured in pixels with an origin in the top left corner.<BR> Dim exportRECT As tagRECT<BR> exportRECT = pActiveView.ExportFrame<BR> <BR> 'Create a new envelope object and populate it with the values from exportRECT.<BR> ' We need to do this because the exporter object requires an envelope object<BR> ' instead of a tagRECT structure.<BR> Dim pPixelBoundsEnv As IEnvelope<BR> Set pPixelBoundsEnv = New Envelope<BR> pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom<BR> <BR> 'Assign the envelope object to the exporter object's PixelBounds property. The exporter object<BR> ' will use these dimensions when allocating memory for the export file.<BR> pExport.PixelBounds = pPixelBoundsEnv</P> <P> 'Initialize the exporter object and store it's device context in the hDC variable. At this method<BR> ' call, the exporter object will create an empty file and allocate memory based on resolution,<BR> ' bit depth, and pixel bounds.<BR> Dim hDC As Long<BR> hDC = pExport.StartExporting<BR> <BR> 'Redraw the active view, rendering it to the exporter object device context instead of the app display.<BR> 'We pass the following values:<BR> ' * hDC is the device context of the exporter object.<BR> ' * pExport.Resolution is 96, the default resolution value for all image export formats. Default screen<BR> ' resolution for MS Windows is usually 96dpi.<BR> ' * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.<BR> ' The values in exportRECT should match those held in the exporter object's PixelBounds property.<BR> pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing<BR> <BR> 'Finish writing the export file and cleanup any intermediate files.<BR> pExport.FinishExporting<BR> pExport.Cleanup<BR> <BR>End Sub</P> <P><BR>Public Sub ExportActiveView2()<BR> Dim pMxDoc As IMxDocument<BR> Dim pActiveView As IActiveView<BR> Dim pExport As IExport<BR> Dim pPixelBoundsEnv As IEnvelope<BR> Dim exportRECT As tagRECT<BR> Dim iOutputResolution As Integer<BR> Dim iScreenResolution As Integer<BR> Dim hDC As Long</P> <P> Set pMxDoc = Application.Document<BR> Set pActiveView = pMxDoc.ActiveView<BR> <BR> Set pExport = New ExportJPEG</P> <P> pExport.ExportFileName = "C:\ExportTest2." ; Right(pExport.Filter, 3)</P> <P> 'Because we are exporting to a resolution that differs from screen resolution, we should<BR> ' assign the two values to variables for use in our sizing calculations<BR> iScreenResolution = 96 'default screen resolution is usually 96dpi<BR> iOutputResolution = 300<BR> pExport.Resolution = iOutputResolution<BR> <BR> 'The ExportFrame property gives us the dimensions appropriate for an export at screen resolution.<BR> ' Because we are exporting at a higher resolution (more pixels), we must multiply each dimesion<BR> ' by the ratio of OutputResolution to ScreenResolution. Instead of assigning the entire<BR> ' ExportFrame directly to the exportRECT, let's bring the values across one at a time and multiply<BR> ' the dimensions.<BR> With exportRECT<BR> .Left = 0<BR> .Top = 0<BR> .Right = pActiveView.ExportFrame.Right * (iOutputResolution / iScreenResolution)<BR> .bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution)<BR> End With<BR> <BR> 'Set up the PixelBounds envelope to match the exportRECT<BR> Set pPixelBoundsEnv = New Envelope<BR> pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom<BR> pExport.PixelBounds = pPixelBoundsEnv<BR> <BR> hDC = pExport.StartExporting<BR> pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing<BR> pExport.FinishExporting<BR> pExport.Cleanup<BR> <BR>End Sub<BR></P> |
|
|
2楼#
发布于:2005-08-08 16:06
<P>感谢GIS大虾的帮助。我也找到了一个用C#实现的办法,不借助显示控件,用Carto中的Map类做容器,IMap和IActiveView接口进行访问。代码如下:</P>
<P>using ESRI.ArcGIS.DataSourcesGDB;<br>using ESRI.ArcGIS.Geodatabase;<br>using ESRI.ArcGIS.Output;<br>using ESRI.ArcGIS.Display;<br>using ESRI.ArcGIS.esriSystem;<br>using ESRI.ArcGIS.Carto;</P> <P>namespace Map<br>{<br>public class GetMap <br>{<br> private string GetJpg()<br> {<br> IWorkspace iWs = openSDEWorkspace("XIANGHUA","esri_sde","sde","sde","sde","SDE.DEFAULT");<br> IFeatureWorkspace iFtWs = (IFeatureWorkspace)iWs;<br> IFeatureClass iFtc = iFtWs.OpenFeatureClass("sde.SDE.county");<br> <br> IMap iMap = new MapClass();<br> IFeatureLayer iFL = new FeatureLayerClass();<br> iFL.FeatureClass = iFtc;<br> iMap.AddLayer((ILayer)iFL);<br> IActiveView iAV = (IActiveView)iMap;</P> <P> IExportJPEG iEpJpg = new ExportJPEGClass();<br> iEpJpg.ProgressiveMode = false;<br> iEpJpg.Quality=100;</P> <P> IExportImage iEpimg = (IExportImage) iEpJpg;<br> iEpimg.ImageType = ESRI.ArcGIS.Output.esriExportImageType.esriExportImageTypeTrueColor;<br> iEpimg.Width = 800;<br> iEpimg.Height = 600;<br> <br> IRgbColor iColor = new RgbColorClass();<br> iColor.Red = 255;<br> iColor.Blue = 255;<br> iColor.Green = 255;<br> iEpimg.BackgroundColor = iColor;<br> <br> IWorldFileSettings iWFS = (IWorldFileSettings)iEpimg;<br> iWFS.OutputWorldFile=false;<br> <br> IExport iEp = (IExport)iWFS;<br><br> iEp.Resolution = 96; //iAV.ScreenDisplay.DisplayTransformation.Resolution; </P> <P> tagRECT userRECT;<br> userRECT.top = 0;<br> userRECT.left = 0;<br> userRECT.right = ConvertRWToPixels(iAV.Extent.Width,iAV);//地理坐标向MAP容器坐标的转化<br> userRECT.bottom = ConvertRWToPixels(iAV.Extent.Height,iAV);//地理坐标向MAP容器坐标的转化</P> <P> iEp.ExportFileName = Server.MapPath(".\\jpg\\Out.jpg");<br><br> int hDc;<br> hDc = iEp.StartExporting();<br> //由MAP容器向图片文件输出<br> iAV.Output(hDc,96,ref userRECT,iAV.Extent,null);<br> iEp.FinishExporting();<br> return iFtc.AliasName;<br> }<br></P> <P> private int ConvertRWToPixels(double RWUnits,IActiveView iAV)<br> {<br> double realWorldDisplayExtent;<br> long pixelExtent;<br> double sizeOfOnePixel;<br> tagRECT deviceRECT;</P> <P> IDisplayTransformation pDT = iAV.ScreenDisplay.DisplayTransformation;<br> deviceRECT = pDT.get_DeviceFrame();<br> pixelExtent = deviceRECT.right - deviceRECT.left;<br> IEnvelope pEnv = pDT.VisibleBounds;</P> <P> realWorldDisplayExtent = pEnv.Width;<br> sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;<br> return (int)(RWUnits / sizeOfOnePixel);<br> }<br>}</P> [此贴子已经被作者于2005-8-8 17:22:54编辑过]
|
|
3楼#
发布于:2005-08-08 17:05
我还想问问怎么导出为PDF、SVG等矢量格式呀?请问各位大虾有范例可以参考吗?
|
|
4楼#
发布于:2005-08-09 14:24
<P>看看帮助里:</P>
<P> <TABLE cellSpacing=4 cols=2 cellPadding=4> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportAI.htm" target="_blank" >ExportAI</A></B></TD> <TD class=t width="65%">Class used to export maps to AI (Adobe Illustrator) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportBMP.htm" target="_blank" >ExportBMP</A></B></TD> <TD class=t width="65%">Class used to export maps to BMP (Windows Bitmap) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportEMF.htm" target="_blank" >ExportEMF</A></B></TD> <TD class=t width="65%">Class used to export maps to EMF (Windows Enhanced Metafile) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportGIF.htm" target="_blank" >ExportGIF</A></B></TD> <TD class=t width="65%">Class used to export maps to GIF (Graphics Interchange Format).</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportJPEG.htm" target="_blank" >ExportJPEG</A></B></TD> <TD class=t width="65%">Class used to export maps to JPEG (Joint Photographic Experts Group) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportPDF.htm" target="_blank" >ExportPDF</A></B></TD> <TD class=t width="65%">Class used to export maps to PDF (Portable Document Format) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportPNG.htm" target="_blank" >ExportPNG</A></B></TD> <TD class=t width="65%">Class used to export maps to PNG (Portable Network Graphics) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportPS.htm" target="_blank" >ExportPS</A></B></TD> <TD class=t width="65%">Class used to export maps to PS (PostScript) and EPS (Encapsulated PostScript) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportSVG.htm" target="_blank" >ExportSVG</A></B></TD> <TD class=t width="65%">Class used to export maps to SVG (Scalable Vector Graphics) format.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/ExportTIFF.htm" target="_blank" >ExportTIFF</A></B></TD> <TD class=t width="65%">Class used to export maps to TIFF (Tagged Image File Format).</TD></TR></TABLE></P> |
|
|
5楼#
发布于:2012-11-26 15:02
求解
|
|
|