tianjuan980106
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数89
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2050回复:4

地图输出成jpg或bmp

楼主#
更多 发布于:2004-10-11 08:14
<P>在engine中,怎么杨把地图输出成jpg或bmp
要用到哪个接口</P>
<P>原来在8。3中的输出接口在engine中没有了, </P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2004-10-12 15:44
<P>This sample demonstrates how to export the active view to any of the ten supported graphics file formats. Using this sample in its current state will export a JPEG file to C:\. You can easily modify it to produce other export formats, saved to a location of your choice. Products:
ArcView: VBA, VC++</P>
<P>
Platforms: Windows</P>
<P>Minimum ArcGIS Release: 9.0
 </P>
<P>How to use:
[VBA]
Paste this code into the Visual Basic editor and select Run Sub from the Run menu.
[VC++]
Paste the function in your project.
Call the function from your code. </P>
<P>
[VBA]
Public Sub ExportActiveView()
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  Dim pActiveView As IActiveView
  Set pActiveView = pMxDoc.ActiveView
  
  'Create an ExportJPEG object and QI the pExport interface pointer onto it.
  ' To export to a format other than JPEG, simply create a different CoClass here
  ' and change the file extension of the ExportFileName.
  Dim pExport As IExport
  Set pExport = New ExportJPEG
  pExport.ExportFileName = "C:\ExportTest1.jpg"</P>
<P>  
  'Set the export object resolution to 96 dpi.  The default screen resolution for
  ' MS Windows is usually 96dpi, and this value is also the default resolution for all
  ' of the ArcGIS image format exporters.  The vector format exporters (PDF, AI, etc.)
  ' default to 300 dpi, so we should explicitly set resolution here to be certain we
  ' are working with a resolution of 96.
  pExport.Resolution = 96
  
  'For both PageLayout and Map objects, the ExportFrame property always holds a tagRECT
  ' structure appropriate for exporting.  The values in the tagRECT correspond to the width
  ' and height to export, measured in pixels with an origin in the top left corner.
  Dim exportRECT As tagRECT
  exportRECT = pActiveView.ExportFrame
  
  'Create a new envelope object and populate it with the values from exportRECT.
  ' We need to do this because the exporter object requires an envelope object
  ' instead of a tagRECT structure.
  Dim pPixelBoundsEnv As IEnvelope
  Set pPixelBoundsEnv = New Envelope
  pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom
  
  'Assign the envelope object to the exporter object's PixelBounds property.  The exporter object
  ' will use these dimensions when allocating memory for the export file.
  pExport.PixelBounds = pPixelBoundsEnv</P>
<P>  'Initialize the exporter object and store it's device context in the hDC variable.  At this method
  ' call, the exporter object will create an empty file and allocate memory based on resolution,
  ' bit depth, and pixel bounds.
  Dim hDC As Long
  hDC = pExport.StartExporting
  
  'Redraw the active view, rendering it to the exporter object device context instead of the app display.
  'We pass the following values:
  ' * hDC is the device context of the exporter object.
  ' * pExport.Resolution is 96, the default resolution value for all image export formats.  Default screen
  ' resolution for MS Windows is usually 96dpi.
  ' * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.
  ' The values in exportRECT should match those held in the exporter object's PixelBounds property.
  pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing
  
  'Finish writing the export file and cleanup any intermediate files.
  pExport.FinishExporting
  pExport.Cleanup
  
End Sub</P>
<P>
Public Sub ExportActiveView2()
  Dim pMxDoc As IMxDocument
  Dim pActiveView As IActiveView
  Dim pExport As IExport
  Dim pPixelBoundsEnv As IEnvelope
  Dim exportRECT As tagRECT
  Dim iOutputResolution As Integer
  Dim iScreenResolution As Integer
  Dim hDC As Long</P>
<P>  Set pMxDoc = Application.Document
  Set pActiveView = pMxDoc.ActiveView
  
  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
  ' assign the two values to variables for use in our sizing calculations
  iScreenResolution = 96  'default screen resolution is usually 96dpi
  iOutputResolution = 300
  pExport.Resolution = iOutputResolution
  
  'The ExportFrame property gives us the dimensions appropriate for an export at screen resolution.
  ' Because we are exporting at a higher resolution (more pixels), we must multiply each dimesion
  ' by the ratio of OutputResolution to ScreenResolution. Instead of assigning the entire
  ' ExportFrame directly to the exportRECT, let's bring the values across one at a time and multiply
  ' the dimensions.
  With exportRECT
    .Left = 0
    .Top = 0
    .Right = pActiveView.ExportFrame.Right * (iOutputResolution / iScreenResolution)
    .bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution)
  End With
  
  'Set up the PixelBounds envelope to match the exportRECT
  Set pPixelBoundsEnv = New Envelope
  pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom
  pExport.PixelBounds = pPixelBoundsEnv
  
  hDC = pExport.StartExporting
  pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing
  pExport.FinishExporting
  pExport.Cleanup
  
End Sub
[VC++]
HRESULT ExportActiveView()
{
  IDocumentPtr ipDoc;
  m_ipApp->get_Document(;ipDoc);
  IMxApplicationPtr ipMxApp(m_ipApp);
  IMxDocumentPtr ipMxDoc(ipDoc);
  IActiveViewPtr ipActiveView;
  ipMxDoc->get_ActiveView(;ipActiveView);</P>
<P>  // Create an ExportJPEG object and QI the pExport interface pointer onto it.
  //  To export to a format other than JPEG, simply create a different CoClass here
  //  and change the file extension of the ExportFileName.
  IExportPtr ipExport(CLSID_ExportJPEG);
  ipExport->put_ExportFileName(L"C:\\ExportTest1.jpg");</P>
<P>  // Set the export object resolution to 96 dpi.  The default screen resolution for
  //  MS Windows is usually 96dpi, and this value is also the default resolution for all
  //  of the ArcGIS image format exporters.  The vector format exporters (PDF, AI, etc.)
  //  default to 300 dpi, so we should explicitly set resolution here to be certain we
  //  are working with a resolution of 96.
  ipExport->put_Resolution(96);</P>
<P>  // For both PageLayout and Map objects, the ExportFrame property always holds a tagRECT
  //  structure appropriate for exporting.  The values in the tagRECT correspond to the width
  //  and height to export, measured in pixels with an origin in the top left corner.
  tagRECT exportRECT;
  ipActiveView->get_ExportFrame(;exportRECT);</P>
<P>  // Create a new envelope object and populate it with the values from exportRECT.
  //  We need to do this because the exporter object requires an envelope object
  //  instead of a tagRECT structure.
  IEnvelopePtr ipPixelBoundsEnv(CLSID_Envelope);
  ipPixelBoundsEnv->PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);</P>
<P>  // Assign the envelope object to the exporter object's PixelBounds property.  The exporter object
  //  will use these dimensions when allocating memory for the export file.
  ipExport->put_PixelBounds(ipPixelBoundsEnv);</P>
<P>  // Initialize the exporter object and store it's device context in the hDC variable.  At this method
  //  call, the exporter object will create an empty file and allocate memory based on resolution,
  //  bit depth, and pixel bounds.
  OLE_HANDLE hDC;
  ipExport->StartExporting(;hDC);</P>
<P>  // Redraw the active view, rendering it to the exporter object device context instead of the app display.
  // We pass the following values:
  //  * hDC is the device context of the exporter object.
  //  * pExport.Resolution is 96, the default resolution value for all image export formats.  Default screen
  //  resolution for MS Windows is usually 96dpi.
  //  * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.
  //  The values in exportRECT should match those held in the exporter object's PixelBounds property.
  double dResolution;
  ipExport->get_Resolution(;dResolution);
  ipActiveView->Output(hDC, (long)dResolution, ;exportRECT, 0, 0);</P>
<P>  // Finish writing the export file and cleanup any intermediate files.
  ipExport->FinishExporting();
  ipExport->Cleanup();</P>
<P>  return S_OK;
}</P>
<P>HRESULT ExportActiveView2()
{
  IDocumentPtr ipDoc;
  m_ipApp->get_Document(;ipDoc);
  IMxApplicationPtr ipMxApp(m_ipApp);
  IMxDocumentPtr ipMxDoc(ipDoc);
  IActiveViewPtr ipActiveView;
  ipMxDoc->get_ActiveView(;ipActiveView);</P>
<P>  IExportPtr ipExport(CLSID_ExportJPEG);
  CComBSTR strFilter;
  ipExport->get_Filter(;strFilter);
  UINT uFilterLength(strFilter.Length() - 3);
  CComBSTR strExtension(L"c:\\ExportTest2.");
  strExtension += _tcsninc(strFilter, uFilterLength);</P>
<P>  ipExport->put_ExportFileName(strExtension);</P>
<P>  // Because we are exporting to a resolution that differs from screen resolution, we should
  //  assign the two values to variables for use in our sizing calculations
  int iScreenResolution = 96;  // default screen resolution is usually 96dpi
  int iOutputResolution = 300;
  ipExport->put_Resolution(iOutputResolution);</P>
<P>  // The ExportFrame property gives us the dimensions appropriate for an export at screen resolution.
  //  Because we are exporting at a higher resolution (more pixels), we must multiply each dimesion
  //  by the ratio of OutputResolution to ScreenResolution. Instead of assigning the entire
  //  ExportFrame directly to the exportRECT, let's bring the values across one at a time and multiply
  //  the dimensions.
  tagRECT exportFrame;
  ipActiveView->get_ExportFrame(;exportFrame);
  tagRECT exportRECT;
  exportRECT.left = 0;
  exportRECT.top = 0;
  exportRECT.right = exportFrame.right * (iOutputResolution / iScreenResolution);
  exportRECT.bottom = exportFrame.bottom * (iOutputResolution / iScreenResolution);</P>
<P>  // Set up the PixelBounds envelope to match the exportRECT
  IEnvelopePtr ipPixelBoundsEnv(CLSID_Envelope);
  ipPixelBoundsEnv->PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
  ipExport->put_PixelBounds(ipPixelBoundsEnv);</P>
<P>  OLE_HANDLE hDC;
  ipExport->StartExporting(;hDC);
  double dResolution;
  ipExport->get_Resolution(;dResolution);
  ipActiveView->Output(hDC, (long)dResolution, ;exportRECT, 0, 0);
  ipExport->FinishExporting();
  ipExport->Cleanup();</P>
<P>  return S_OK;
}
</P>
[此贴子已经被作者于2004-10-12 15:46:02编辑过]
举报 回复(0) 喜欢(0)     评分
tianjuan980106
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数89
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-10-12 22:59
<P>非常感谢gis !!!,</P><P>可能是我的问题没有说清楚,</P><P>在8.3和9.0中,IExport是存在的,但是在engine中,这个接口不存在了。</P><P>上面的代码,在独立的engine环境中,是不能使用的,我想在独立的engine环境中,实现我说的功能,
</P>
举报 回复(0) 喜欢(0)     评分
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-10-14 14:21
<DIV class=quote><B>以下是引用<I>tianjuan980106</I>在2004-10-12 22:59:19的发言:</B>

<P>非常感谢gis !!!,</P>
<P>可能是我的问题没有说清楚,</P>
<P>在8.3和9.0中,IExport是存在的,但是在engine中,这个接口不存在了。</P>
<P>上面的代码,在独立的engine环境中,是不能使用的,我想在独立的engine环境中,实现我说的功能,
</P></DIV>
<P>
<P>你查了帮助了么?这是我在9.0帮助中看到的:</P>
<H1>IExport Interface (<a href="mk:@MSITStore:D:\ArcGIS\DeveloperKit\Help\COM\VB\esriOutput.chm::/Output_library.htm" target="_blank" >esriOutput</A>)</H1>


<P></P>
<P>Provides access to members that control the Export. </P>
<P><B>Product Availability</B></P>
<DIV>Available with<FONT color=#ff0000> ArcGIS Engine</FONT>, ArcGIS Desktop, and ArcGIS Server.</DIV>
举报 回复(0) 喜欢(0)     评分
tianjuan980106
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数89
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2004-10-18 15:15
<P>谢谢,我找到了,你说的是对的,</P><P>开始的时候,我是在ae的uml中找的,没有找到,但是在帮助中还是有的,</P><P>谢谢!!!</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部